Remove \n from log messages
[freeradius.git] / src / modules / rlm_eap / libeap / cb.c
1 /*
2  * cb.c
3  *
4  * Version:     $Id$
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2001  hereUare Communications, Inc. <raghud@hereuare.com>
21  * Copyright 2006  The FreeRADIUS server project
22  */
23
24 #include <freeradius-devel/ident.h>
25 RCSID("$Id$")
26
27 #include "eap_tls.h"
28
29 #ifndef NO_OPENSSL
30
31 void cbtls_info(const SSL *s, int where, int ret)
32 {
33         const char *str, *state;
34         int w;
35         EAP_HANDLER *handler = (EAP_HANDLER *)SSL_get_ex_data(s, 0);
36         REQUEST *request = NULL;
37         char buffer[1024];
38
39         if (handler) request = handler->request;
40
41         w = where & ~SSL_ST_MASK;
42         if (w & SSL_ST_CONNECT) str="    TLS_connect";
43         else if (w & SSL_ST_ACCEPT) str="    TLS_accept";
44         else str="    (other)";
45
46         state = SSL_state_string_long(s);
47         state = state ? state : "NULL";
48         buffer[0] = '\0';
49
50         if (where & SSL_CB_LOOP) {
51                 RDEBUG2("%s: %s", str, state);
52         } else if (where & SSL_CB_HANDSHAKE_START) {
53                 RDEBUG2("%s: %s", str, state);
54         } else if (where & SSL_CB_HANDSHAKE_DONE) {
55                 RDEBUG2("%s: %s", str, state);
56         } else if (where & SSL_CB_ALERT) {
57                 str=(where & SSL_CB_READ)?"read":"write";
58
59                 snprintf(buffer, sizeof(buffer), "TLS Alert %s:%s:%s",
60                          str,
61                          SSL_alert_type_string_long(ret),
62                          SSL_alert_desc_string_long(ret));
63         } else if (where & SSL_CB_EXIT) {
64                 if (ret == 0) {
65                         snprintf(buffer, sizeof(buffer), "%s: failed in %s",
66                                  str, state);
67
68                 } else if (ret < 0) {
69                         if (SSL_want_read(s)) {
70                                 RDEBUG2("%s: Need to read more data: %s",
71                                        str, state);
72                         } else {
73                                 snprintf(buffer, sizeof(buffer),
74                                          "%s: error in %s", str, state);
75                         }
76                 }
77         }
78
79         if (buffer[0]) {
80                 radlog(L_ERR, "%s", buffer);
81                 
82                 if (request) {
83                         VALUE_PAIR *vp;
84                         
85                         vp = pairmake("Module-Failure-Message", buffer, T_OP_ADD);
86                         if (vp) pairadd(&request->packet->vps, vp);
87                 }
88         }
89 }
90
91 /*
92  *      Fill in our 'info' with TLS data.
93  */
94 void cbtls_msg(int write_p, int msg_version, int content_type,
95                const void *buf, size_t len,
96                SSL *ssl UNUSED, void *arg)
97 {
98         tls_session_t *state = (tls_session_t *)arg;
99
100         /*
101          *      Work around bug #298, where we may be called with a NULL
102          *      argument.  We should really log a serious error
103          */
104         if (!arg) return;
105
106         state->info.origin = (unsigned char)write_p;
107         state->info.content_type = (unsigned char)content_type;
108         state->info.record_len = len;
109         state->info.version = msg_version;
110         state->info.initialized = 1;
111
112         if (content_type == SSL3_RT_ALERT) {
113                 state->info.alert_level = ((const unsigned char*)buf)[0];
114                 state->info.alert_description = ((const unsigned char*)buf)[1];
115                 state->info.handshake_type = 0x00;
116
117         } else if (content_type == SSL3_RT_HANDSHAKE) {
118                 state->info.handshake_type = ((const unsigned char*)buf)[0];
119                 state->info.alert_level = 0x00;
120                 state->info.alert_description = 0x00;
121         }
122         tls_session_information(state);
123 }
124
125 int cbtls_password(char *buf,
126                    int num UNUSED,
127                    int rwflag UNUSED,
128                    void *userdata)
129 {
130         strcpy(buf, (char *)userdata);
131         return(strlen((char *)userdata));
132 }
133
134 /*
135  *      For callbacks
136  */
137 int eaptls_handle_idx = -1;
138 int eaptls_conf_idx = -1;
139 int eaptls_session_idx = -1;
140
141 #endif /* !defined(NO_OPENSSL) */