~ubuntu-branches/ubuntu/oneiric/strongswan/oneiric

« back to all changes in this revision

Viewing changes to src/starter/loglite.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2009-04-18 20:28:51 UTC
  • mfrom: (1.1.9 upstream) (2.1.15 karmic)
  • Revision ID: james.westby@ubuntu.com-20090418202851-ep722qhmzvpxh6yj
Tags: 4.3.2-1
Urgency high because of security issue and FTBFS.
* New upstream release, fixes security bug.
* Fix padlock handling for i386 in debian/rules.
  Closes: #525652 (FTBFS on i386)
* Acknowledge NMUs by security team.
  Closes: #533837, #531612
* Add "Conflicts: strongswan (< 4.2.12-1)" to libstrongswan, 
  strongswan-starter, strongswan-ikev1, and strongswan-ikev2 to force
  update of the strongswan package on installation and avoid conflicts
  caused by package restructuring.
  Closes: #526037: strongswan-ikev2 and strongswan: error when trying to 
                   install together
  Closes: #526486: strongswan and libstrongswan: error when trying to 
                   install together
  Closes: #526487: strongswan-ikev1 and strongswan: error when trying to 
                   install together
  Closes: #526488: strongswan-starter and strongswan: error when trying to 
                   install together
* Debconf templates and debian/control reviewed by the debian-l10n-
  english team as part of the Smith review project. Closes: #528073
* Debconf translation updates:
  Closes: #525234: [INTL:ja] Update po-debconf template translation (ja.po) 
  Closes: #528323: [INTL:sv] po-debconf file for strongswan 
  Closes: #528370: [INTL:vi] Vietnamese debconf templates translation update 
  Closes: #529027: [INTL:pt] Updated Portuguese translation for debconf messages
  Closes: #529071: [INTL:fr] French debconf templates translation update 
  Closes: #529592: nb translation of debconf PO for strongSWAN 
  Closes: #529638: [INTL:ru] Russian debconf templates translation 
  Closes: #529661: Updated Czech translation of strongswan debconf messages 
  Closes: #529742: [INTL:eu] strongswan debconf basque translation 
  Closes: #530273: [INTL:fi] Finnish translation of the debconf templates
  Closes: #529063: [INTL:gl] strongswan 4.2.14-2 debconf translation update

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
12
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
13
 * for more details.
14
 
 *
15
 
 * RCSID $Id: loglite.c 3267 2007-10-08 19:57:54Z andreas $
16
14
 */
17
15
 
18
16
#include <stdio.h>
23
21
#include <errno.h>
24
22
#include <string.h>
25
23
#include <unistd.h>
26
 
#include <signal.h>     /* used only if MSG_NOSIGNAL not defined */
 
24
#include <signal.h>     /* used only if MSG_NOSIGNAL not defined */
27
25
#include <libgen.h>
28
26
#include <sys/stat.h>
29
27
#include <sys/types.h>
36
34
#include <whack.h>
37
35
 
38
36
bool
39
 
    log_to_stderr = FALSE,      /* should log go to stderr? */
40
 
    log_to_syslog = TRUE;       /* should log go to syslog? */
 
37
        log_to_stderr = FALSE,      /* should log go to stderr? */
 
38
        log_to_syslog = TRUE;       /* should log go to syslog? */
41
39
 
42
40
void
43
41
init_log(const char *program)
44
42
{
45
 
    if (log_to_stderr)
46
 
        setbuf(stderr, NULL);
47
 
    if (log_to_syslog)
48
 
        openlog(program, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
 
43
        if (log_to_stderr)
 
44
                setbuf(stderr, NULL);
 
45
        if (log_to_syslog)
 
46
                openlog(program, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
49
47
}
50
48
 
51
49
void
52
50
close_log(void)
53
51
{
54
 
    if (log_to_syslog)
55
 
        closelog();
 
52
        if (log_to_syslog)
 
53
                closelog();
56
54
}
57
55
 
58
56
void
59
57
plog(const char *message, ...)
60
58
{
61
 
    va_list args;
62
 
    char m[LOG_WIDTH];  /* longer messages will be truncated */
63
 
 
64
 
    va_start(args, message);
65
 
    vsnprintf(m, sizeof(m), message, args);
66
 
    va_end(args);
67
 
 
68
 
    if (log_to_stderr)
69
 
        fprintf(stderr, "%s\n", m);
70
 
    if (log_to_syslog)
71
 
        syslog(LOG_WARNING, "%s", m);
 
59
        va_list args;
 
60
        char m[LOG_WIDTH];  /* longer messages will be truncated */
 
61
 
 
62
        va_start(args, message);
 
63
        vsnprintf(m, sizeof(m), message, args);
 
64
        va_end(args);
 
65
 
 
66
        if (log_to_stderr)
 
67
                fprintf(stderr, "%s\n", m);
 
68
        if (log_to_syslog)
 
69
                syslog(LOG_WARNING, "%s", m);
72
70
}
73
71
 
74
72
void
75
73
loglog(int mess_no, const char *message, ...)
76
74
{
77
 
    va_list args;
78
 
    char m[LOG_WIDTH];  /* longer messages will be truncated */
79
 
 
80
 
    va_start(args, message);
81
 
    vsnprintf(m, sizeof(m), message, args);
82
 
    va_end(args);
83
 
 
84
 
    if (log_to_stderr)
85
 
        fprintf(stderr, "%s\n", m);
86
 
    if (log_to_syslog)
87
 
        syslog(LOG_WARNING, "%s", m);
 
75
        va_list args;
 
76
        char m[LOG_WIDTH];  /* longer messages will be truncated */
 
77
 
 
78
        va_start(args, message);
 
79
        vsnprintf(m, sizeof(m), message, args);
 
80
        va_end(args);
 
81
 
 
82
        if (log_to_stderr)
 
83
                fprintf(stderr, "%s\n", m);
 
84
        if (log_to_syslog)
 
85
                syslog(LOG_WARNING, "%s", m);
88
86
}
89
87
 
90
88
void
91
89
log_errno_routine(int e, const char *message, ...)
92
90
{
93
 
    va_list args;
94
 
    char m[LOG_WIDTH];  /* longer messages will be truncated */
95
 
 
96
 
    va_start(args, message);
97
 
    vsnprintf(m, sizeof(m), message, args);
98
 
    va_end(args);
99
 
 
100
 
    if (log_to_stderr)
101
 
        fprintf(stderr, "ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
102
 
    if (log_to_syslog)
103
 
        syslog(LOG_ERR, "ERROR: %s. Errno %d: %s", m, e, strerror(e));
 
91
        va_list args;
 
92
        char m[LOG_WIDTH];  /* longer messages will be truncated */
 
93
 
 
94
        va_start(args, message);
 
95
        vsnprintf(m, sizeof(m), message, args);
 
96
        va_end(args);
 
97
 
 
98
        if (log_to_stderr)
 
99
                fprintf(stderr, "ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
 
100
        if (log_to_syslog)
 
101
                syslog(LOG_ERR, "ERROR: %s. Errno %d: %s", m, e, strerror(e));
104
102
}
105
103
 
106
104
void
107
105
exit_log(const char *message, ...)
108
106
{
109
 
    va_list args;
110
 
    char m[LOG_WIDTH];  /* longer messages will be truncated */
111
 
 
112
 
    va_start(args, message);
113
 
    vsnprintf(m, sizeof(m), message, args);
114
 
    va_end(args);
115
 
 
116
 
    if (log_to_stderr)
117
 
        fprintf(stderr, "FATAL ERROR: %s\n", m);
118
 
    if (log_to_syslog)
119
 
        syslog(LOG_ERR, "FATAL ERROR: %s", m);
120
 
    exit(1);
 
107
        va_list args;
 
108
        char m[LOG_WIDTH];  /* longer messages will be truncated */
 
109
 
 
110
        va_start(args, message);
 
111
        vsnprintf(m, sizeof(m), message, args);
 
112
        va_end(args);
 
113
 
 
114
        if (log_to_stderr)
 
115
                fprintf(stderr, "FATAL ERROR: %s\n", m);
 
116
        if (log_to_syslog)
 
117
                syslog(LOG_ERR, "FATAL ERROR: %s", m);
 
118
        exit(1);
121
119
}
122
120
 
123
121
void
124
122
exit_log_errno_routine(int e, const char *message, ...)
125
123
{
126
 
    va_list args;
127
 
    char m[LOG_WIDTH];  /* longer messages will be truncated */
128
 
 
129
 
    va_start(args, message);
130
 
    vsnprintf(m, sizeof(m), message, args);
131
 
    va_end(args);
132
 
 
133
 
    if (log_to_stderr)
134
 
        fprintf(stderr, "FATAL ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
135
 
    if (log_to_syslog)
136
 
        syslog(LOG_ERR, "FATAL ERROR: %s. Errno %d: %s", m, e, strerror(e));
137
 
    exit(1);
 
124
        va_list args;
 
125
        char m[LOG_WIDTH];  /* longer messages will be truncated */
 
126
 
 
127
        va_start(args, message);
 
128
        vsnprintf(m, sizeof(m), message, args);
 
129
        va_end(args);
 
130
 
 
131
        if (log_to_stderr)
 
132
                fprintf(stderr, "FATAL ERROR: %s. Errno %d: %s\n", m, e, strerror(e));
 
133
        if (log_to_syslog)
 
134
                syslog(LOG_ERR, "FATAL ERROR: %s. Errno %d: %s", m, e, strerror(e));
 
135
        exit(1);
138
136
}
139
137
 
140
138
void
141
139
whack_log(int mess_no, const char *message, ...)
142
140
{
143
 
    va_list args;
144
 
    char m[LOG_WIDTH];  /* longer messages will be truncated */
145
 
 
146
 
    va_start(args, message);
147
 
    vsnprintf(m, sizeof(m), message, args);
148
 
    va_end(args);
149
 
 
150
 
    fprintf(stderr, "%s\n", m);
 
141
        va_list args;
 
142
        char m[LOG_WIDTH];  /* longer messages will be truncated */
 
143
 
 
144
        va_start(args, message);
 
145
        vsnprintf(m, sizeof(m), message, args);
 
146
        va_end(args);
 
147
 
 
148
        fprintf(stderr, "%s\n", m);
151
149
}
152
150
 
153
151
/* Build up a diagnostic in a static buffer.
165
163
err_t
166
164
builddiag(const char *fmt, ...)
167
165
{
168
 
    static char diag_space[LOG_WIDTH];  /* longer messages will be truncated */
169
 
    char t[sizeof(diag_space)]; /* build result here first */
170
 
    va_list args;
 
166
        static char diag_space[LOG_WIDTH];  /* longer messages will be truncated */
 
167
        char t[sizeof(diag_space)]; /* build result here first */
 
168
        va_list args;
171
169
 
172
 
    va_start(args, fmt);
173
 
    t[0] = '\0';        /* in case nothing terminates string */
174
 
    vsnprintf(t, sizeof(t), fmt, args);
175
 
    va_end(args);
176
 
    strcpy(diag_space, t);
177
 
    return diag_space;
 
170
        va_start(args, fmt);
 
171
        t[0] = '\0';        /* in case nothing terminates string */
 
172
        vsnprintf(t, sizeof(t), fmt, args);
 
173
        va_end(args);
 
174
        strcpy(diag_space, t);
 
175
        return diag_space;
178
176
}
179
177
 
180
178
/* Debugging message support */
184
182
void
185
183
switch_fail(int n, const char *file_str, unsigned long line_no)
186
184
{
187
 
    char buf[30];
 
185
        char buf[30];
188
186
 
189
 
    snprintf(buf, sizeof(buf), "case %d unexpected", n);
190
 
    passert_fail(buf, file_str, line_no);
 
187
        snprintf(buf, sizeof(buf), "case %d unexpected", n);
 
188
        passert_fail(buf, file_str, line_no);
191
189
}
192
190
 
193
191
void
194
192
passert_fail(const char *pred_str, const char *file_str, unsigned long line_no)
195
193
{
196
 
    /* we will get a possibly unplanned prefix.  Hope it works */
197
 
    loglog(RC_LOG_SERIOUS, "ASSERTION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
198
 
    abort();    /* exiting correctly doesn't always work */
 
194
        /* we will get a possibly unplanned prefix.  Hope it works */
 
195
        loglog(RC_LOG_SERIOUS, "ASSERTION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
 
196
        abort();    /* exiting correctly doesn't always work */
199
197
}
200
198
 
201
199
lset_t
202
 
    base_debugging = DBG_NONE,  /* default to reporting nothing */
203
 
    cur_debugging =  DBG_NONE;
 
200
        base_debugging = DBG_NONE,  /* default to reporting nothing */
 
201
        cur_debugging =  DBG_NONE;
204
202
 
205
203
void
206
204
pexpect_log(const char *pred_str, const char *file_str, unsigned long line_no)
207
205
{
208
 
    /* we will get a possibly unplanned prefix.  Hope it works */
209
 
    loglog(RC_LOG_SERIOUS, "EXPECTATION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
 
206
        /* we will get a possibly unplanned prefix.  Hope it works */
 
207
        loglog(RC_LOG_SERIOUS, "EXPECTATION FAILED at %s:%lu: %s", file_str, line_no, pred_str);
210
208
}
211
209
 
212
210
/* log a debugging message (prefixed by "| ") */
214
212
void
215
213
DBG_log(const char *message, ...)
216
214
{
217
 
    va_list args;
218
 
    char m[LOG_WIDTH];  /* longer messages will be truncated */
219
 
 
220
 
    va_start(args, message);
221
 
    vsnprintf(m, sizeof(m), message, args);
222
 
    va_end(args);
223
 
 
224
 
    if (log_to_stderr)
225
 
        fprintf(stderr, "| %s\n", m);
226
 
    if (log_to_syslog)
227
 
        syslog(LOG_DEBUG, "| %s", m);
 
215
        va_list args;
 
216
        char m[LOG_WIDTH];  /* longer messages will be truncated */
 
217
 
 
218
        va_start(args, message);
 
219
        vsnprintf(m, sizeof(m), message, args);
 
220
        va_end(args);
 
221
 
 
222
        if (log_to_stderr)
 
223
                fprintf(stderr, "| %s\n", m);
 
224
        if (log_to_syslog)
 
225
                syslog(LOG_DEBUG, "| %s", m);
228
226
}
229
227
 
230
228
/* dump raw bytes in hex to stderr (for lack of any better destination) */
232
230
void
233
231
DBG_dump(const char *label, const void *p, size_t len)
234
232
{
235
 
#   define DUMP_LABEL_WIDTH 20  /* arbitrary modest boundary */
236
 
#   define DUMP_WIDTH   (4 * (1 + 4 * 3) + 1)
237
 
    char buf[DUMP_LABEL_WIDTH + DUMP_WIDTH];
238
 
    char *bp;
239
 
    const unsigned char *cp = p;
240
 
 
241
 
    bp = buf;
242
 
 
243
 
    if (label != NULL && label[0] != '\0')
244
 
    {
245
 
        /* Handle the label.  Care must be taken to avoid buffer overrun. */
246
 
        size_t llen = strlen(label);
247
 
 
248
 
        if (llen + 1 > sizeof(buf))
249
 
        {
250
 
            DBG_log("%s", label);
251
 
        }
252
 
        else
253
 
        {
254
 
            strcpy(buf, label);
255
 
            if (buf[llen-1] == '\n')
256
 
            {
257
 
                buf[llen-1] = '\0';     /* get rid of newline */
258
 
                DBG_log("%s", buf);
259
 
            }
260
 
            else if (llen < DUMP_LABEL_WIDTH)
261
 
            {
262
 
                bp = buf + llen;
263
 
            }
264
 
            else
265
 
            {
266
 
                DBG_log("%s", buf);
267
 
            }
268
 
        }
269
 
    }
270
 
 
271
 
    do {
272
 
        int i, j;
273
 
 
274
 
        for (i = 0; len!=0 && i!=4; i++)
275
 
        {
276
 
            *bp++ = ' ';
277
 
            for (j = 0; len!=0 && j!=4; len--, j++)
278
 
            {
279
 
                static const char hexdig[] = "0123456789abcdef";
280
 
 
281
 
                *bp++ = ' ';
282
 
                *bp++ = hexdig[(*cp >> 4) & 0xF];
283
 
                *bp++ = hexdig[*cp & 0xF];
284
 
                cp++;
285
 
            }
286
 
        }
287
 
        *bp = '\0';
288
 
        DBG_log("%s", buf);
 
233
#   define DUMP_LABEL_WIDTH 20  /* arbitrary modest boundary */
 
234
#   define DUMP_WIDTH   (4 * (1 + 4 * 3) + 1)
 
235
        char buf[DUMP_LABEL_WIDTH + DUMP_WIDTH];
 
236
        char *bp;
 
237
        const unsigned char *cp = p;
 
238
 
289
239
        bp = buf;
290
 
    } while (len != 0);
 
240
 
 
241
        if (label != NULL && label[0] != '\0')
 
242
        {
 
243
                /* Handle the label.  Care must be taken to avoid buffer overrun. */
 
244
                size_t llen = strlen(label);
 
245
 
 
246
                if (llen + 1 > sizeof(buf))
 
247
                {
 
248
                        DBG_log("%s", label);
 
249
                }
 
250
                else
 
251
                {
 
252
                        strcpy(buf, label);
 
253
                        if (buf[llen-1] == '\n')
 
254
                        {
 
255
                                buf[llen-1] = '\0';     /* get rid of newline */
 
256
                                DBG_log("%s", buf);
 
257
                        }
 
258
                        else if (llen < DUMP_LABEL_WIDTH)
 
259
                        {
 
260
                                bp = buf + llen;
 
261
                        }
 
262
                        else
 
263
                        {
 
264
                                DBG_log("%s", buf);
 
265
                        }
 
266
                }
 
267
        }
 
268
 
 
269
        do {
 
270
                int i, j;
 
271
 
 
272
                for (i = 0; len!=0 && i!=4; i++)
 
273
                {
 
274
                        *bp++ = ' ';
 
275
                        for (j = 0; len!=0 && j!=4; len--, j++)
 
276
                        {
 
277
                                static const char hexdig[] = "0123456789abcdef";
 
278
 
 
279
                                *bp++ = ' ';
 
280
                                *bp++ = hexdig[(*cp >> 4) & 0xF];
 
281
                                *bp++ = hexdig[*cp & 0xF];
 
282
                                cp++;
 
283
                        }
 
284
                }
 
285
                *bp = '\0';
 
286
                DBG_log("%s", buf);
 
287
                bp = buf;
 
288
        } while (len != 0);
291
289
#   undef DUMP_LABEL_WIDTH
292
290
#   undef DUMP_WIDTH
293
291
}