Add config item to toggle openssl vulnerability check
[freeradius.git] / src / main / version.c
1 /*
2  * version.c    Print version number and exit.
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 1999-2014  The FreeRADIUS server project
21  * Copyright 2012  Alan DeKok <aland@ox.org>
22  * Copyright 2000  Chris Parker <cparker@starnetusa.com>
23  */
24
25 RCSID("$Id$")
26
27 #include <freeradius-devel/radiusd.h>
28 USES_APPLE_DEPRECATED_API       /* OpenSSL API has been deprecated by Apple */
29
30 static uint64_t libmagic = RADIUSD_MAGIC_NUMBER;
31
32 #ifdef HAVE_OPENSSL_CRYPTO_H
33 #  include <openssl/crypto.h>
34 #  include <openssl/opensslv.h>
35
36 static long ssl_built = OPENSSL_VERSION_NUMBER;
37
38 /** Check build and linked versions of OpenSSL match
39  *
40  * Startup check for whether the linked version of OpenSSL matches the
41  * version the server was built against.
42  *
43  * @return 0 if ok, else -1
44  */
45 int ssl_check_consistency(void)
46 {
47         long ssl_linked;
48
49         ssl_linked = SSLeay();
50
51         if (ssl_linked != ssl_built) {
52                 ERROR("libssl version mismatch.  built: %lx linked: %lx",
53                        (unsigned long) ssl_built,
54                        (unsigned long) ssl_linked);
55
56                 return -1;
57         };
58
59         return 0;
60 }
61
62 /** Print the current linked version of Openssl
63  *
64  * Print the currently linked version of the OpenSSL library.
65  */
66 char const *ssl_version(void)
67 {
68         static char buffer[1024];
69         uint64_t v;
70
71         /* OpenSSL represents the version as a 36bit unsigned integer */
72         v = (uint64_t) SSLeay();
73
74         snprintf(buffer, sizeof(buffer), "%s 0x%.9" PRIx64 " (%i.%i.%i%c %i)",
75                  SSLeay_version(SSLEAY_VERSION),                /* Not all builds include a useful version number */
76                  v,
77                  (int) ((0x0000000ff0000000 & v) >> 28),
78                  (int) ((0x000000000ff00000 & v) >> 20),
79                  (int) ((0x00000000000ff000 & v) >> 12),
80                  (char)((0x0000000000000ff0 & v) >> 4 ? (0x60 + ((0x000000000000ff0 & v) >> 4)) : ' '),
81                  (int) ((0x000000000000000f & v)));
82
83         return buffer;
84 }
85 #  else
86 int ssl_check_consistency(void) {
87         return 0;
88 }
89
90 char const *ssl_version()
91 {
92         return "not linked";
93 }
94 #endif /* ifdef HAVE_OPENSSL_CRYPTO_H */
95
96
97 /** Check if the application linking to the library has the correct magic number
98  *
99  * @param magic number as defined by RADIUSD_MAGIC_NUMBER
100  * @returns 0 on success, -1 on prefix mismatch, -2 on version mismatch -3 on commit mismatch.
101  */
102 int rad_check_lib_magic(uint64_t magic)
103 {
104         if (MAGIC_PREFIX(magic) != MAGIC_PREFIX(libmagic)) {
105                 ERROR("Application and libfreeradius-server magic number (prefix) mismatch."
106                       "  application: %x library: %x",
107                       MAGIC_PREFIX(magic), MAGIC_PREFIX(libmagic));
108                 return -1;
109         }
110
111         if (MAGIC_VERSION(magic) != MAGIC_VERSION(libmagic)) {
112                 ERROR("Application and libfreeradius-server magic number (version) mismatch."
113                       "  application: %lx library: %lx",
114                       (unsigned long) MAGIC_VERSION(magic), (unsigned long) MAGIC_VERSION(libmagic));
115                 return -2;
116         }
117
118         if (MAGIC_COMMIT(magic) != MAGIC_COMMIT(libmagic)) {
119                 ERROR("Application and libfreeradius-server magic number (commit) mismatch."
120                       "  application: %lx library: %lx",
121                       (unsigned long) MAGIC_COMMIT(magic), (unsigned long) MAGIC_COMMIT(libmagic));
122                 return -3;
123         }
124
125         return 0;
126 }
127
128 /*
129  *      Display the revision number for this program
130  */
131 void version(void)
132 {
133         INFO("%s: %s", progname, radiusd_version);
134
135         DEBUG3("Server was built with: ");
136
137 #ifdef WITH_ACCOUNTING
138         DEBUG3("  accounting");
139 #endif
140         DEBUG3("  authentication"); /* always enabled */
141
142 #ifdef WITH_ASCEND_BINARY
143         DEBUG3("  ascend binary attributes");
144 #endif
145 #ifdef WITH_COA
146         DEBUG3("  coa");
147 #endif
148 #ifdef WITH_COMMAND_SOCKET
149         DEBUG3("  control-socket");
150 #endif
151 #ifdef WITH_DETAIL
152         DEBUG3("  detail");
153 #endif
154 #ifdef WITH_DHCP
155         DEBUG3("  dhcp");
156 #endif
157 #ifdef WITH_DYNAMIC_CLIENTS
158         DEBUG3("  dynamic clients");
159 #endif
160 #ifdef OSFC2
161         DEBUG3("  OSFC2");
162 #endif
163 #ifdef WITH_PROXY
164         DEBUG3("  proxy");
165 #endif
166 #ifdef HAVE_PCREPOSIX_H
167         DEBUG3("  regex-pcre");
168 #else
169 #ifdef HAVE_REGEX_H
170         DEBUG3("  regex-posix");
171 #endif
172 #endif
173
174 #ifdef WITH_SESSION_MGMT
175         DEBUG3("  session-management");
176 #endif
177 #ifdef WITH_STATS
178         DEBUG3("  stats");
179 #endif
180 #ifdef WITH_TCP
181         DEBUG3("  tcp");
182 #endif
183 #ifdef WITH_THREADS
184         DEBUG3("  threads");
185 #endif
186 #ifdef WITH_TLS
187         DEBUG3("  tls");
188 #endif
189 #ifdef WITH_UNLANG
190         DEBUG3("  unlang");
191 #endif
192 #ifdef WITH_VMPS
193         DEBUG3("  vmps");
194 #endif
195
196         DEBUG3("Server core libs:");
197         DEBUG3("  talloc : %i.%i.*", talloc_version_major(), talloc_version_minor());
198         DEBUG3("  ssl    : %s", ssl_version());
199
200         DEBUG3("Library magic number:");
201         DEBUG3("  0x%llx", (unsigned long long) libmagic);
202
203         DEBUG3("Endianess:");
204 #if defined(LITTLE_ENDIAN)
205         DEBUG3("  little");
206 #elif defined(BIG_ENDIAN)
207         DEBUG3("  big");
208 #else
209         DEBUG3("  unknown");
210 #endif
211
212         INFO("Copyright (C) 1999-2014 The FreeRADIUS server project and contributors");
213         INFO("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A");
214         INFO("PARTICULAR PURPOSE");
215         INFO("You may redistribute copies of FreeRADIUS under the terms of the");
216         INFO("GNU General Public License");
217         INFO("For more information about these matters, see the file named COPYRIGHT");
218
219         fflush(NULL);
220 }
221