File: fwknopd_errors.c

package info (click to toggle)
fwknop 2.0.0rc2-2%2Bdeb7u2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,656 kB
  • sloc: ansic: 12,916; sh: 10,743; perl: 545; makefile: 266
file content (110 lines) | stat: -rw-r--r-- 3,385 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* $Id$
 *****************************************************************************
 *
 * File:    errors.c
 *
 * Author:  Damien S. Stuart
 *
 * Purpose: Error message functions for fwknopd
 *
 * Copyright 2010 Damien Stuart (dstuart@dstuart.org)
 *
 *  License (GNU Public License):
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *  USA
 *
 *****************************************************************************
*/
#include "fwknopd_common.h"
#include "fwknopd_errors.h"

/* Attempt to determine the error code type and send the appropriate
 * response. Basically assume it is a libfko error if it is not an fwknopd
 * error code.
*/
const char*
get_errstr(int err_code)
{
    if(! IS_FWKNOPD_ERROR(err_code))
        return(fko_errstr(err_code));

    return(fwknopd_errstr(err_code));
}

/* Return a string describing the meaning of the given error code.
*/
const char*
fwknopd_errstr(int err_code)
{
    switch (err_code)
    {
        case 0:
            return("Success");

        case SPA_MSG_BAD_DATA:
            return("Data is not a valid SPA message format");

        case SPA_MSG_LEN_TOO_SMALL:
            return("Not enough data to be a valid SPA message");

        case SPA_MSG_NOT_SPA_DATA:
            return("Data is not a SPA message");

        case SPA_MSG_HTTP_NOT_ENABLED:
            return("SPA via HTTP request, but ENABLE_SPA_OVER_HTTP is not set");

        case SPA_MSG_FKO_CTX_ERROR:
            return("Error creating FKO context for incoming data.");

        case SPA_MSG_DIGEST_ERROR:
            return("Unable to retrieve digest in from the SPA data.");

        case SPA_MSG_DIGEST_CACHE_ERROR:
            return("Error trying to access the digest.cache file");

        case SPA_MSG_REPLAY:
            return("Detected SPA message replay");

        case SPA_MSG_TOO_OLD:
            return("SPA message timestamp is outside the allowable window");

        case SPA_MSG_ACCESS_DENIED:
            return("SPA message did not pass access checks");

        case SPA_MSG_COMMAND_ERROR:
            return("An error occurred while executing an SPA command message");

        case SPA_MSG_NOT_SUPPORTED:
            return("Unsupported SPA message operation");

        case SPA_MSG_ERROR:
            return("General SPA message processing error");

        case FW_RULE_ADD_ERROR:
            return("An error occurred while tring to add a firewall rule");

        case FW_RULE_DELETE_ERROR:
            return("An error occurred while tring to delete a firewall rule");

        case FW_RULE_UNKNOWN_ERROR:
            return("Unknown/unclassified firewall rule processing error");
    }

    return("Undefined/unknown fwknopd Error");
}


/***EOF***/