2 * version.c Print version number and exit.
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.
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.
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
20 * Copyright 1999-2014 The FreeRADIUS server project
21 * Copyright 2012 Alan DeKok <aland@ox.org>
22 * Copyright 2000 Chris Parker <cparker@starnetusa.com>
27 #include <freeradius-devel/radiusd.h>
28 USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */
30 static uint64_t libmagic = RADIUSD_MAGIC_NUMBER;
32 #ifdef HAVE_OPENSSL_CRYPTO_H
33 # include <openssl/crypto.h>
34 # include <openssl/opensslv.h>
36 static long ssl_built = OPENSSL_VERSION_NUMBER;
38 /** Check built and linked versions of OpenSSL match
40 * OpenSSL version number consists of:
41 * MMNNFFPPS: major minor fix patch status
43 * Where status >= 0 && < 10 means beta, and status 10 means release.
45 * Startup check for whether the linked version of OpenSSL matches the
46 * version the server was built against.
48 * @return 0 if ok, else -1
50 int ssl_check_consistency(void)
54 ssl_linked = SSLeay();
57 * Status mismatch always triggers error.
59 if ((ssl_linked & 0x00000000f) != (ssl_built & 0x00000000f)) {
61 ERROR("libssl version mismatch. built: %lx linked: %lx",
62 (unsigned long) ssl_built,
63 (unsigned long) ssl_linked);
69 * Use the OpenSSH approach and relax fix checks after version
70 * 1.0.0 and only allow moving backwards within a patch
73 if (ssl_built & 0xff) {
74 if ((ssl_built & 0xffff) != (ssl_linked & 0xffff) ||
75 (ssl_built & 0x0000ff) > (ssl_linked & 0x0000ff)) goto mismatch;
77 * Before 1.0.0 we require the same major minor and fix version
78 * and ignore the patch number.
80 } else if ((ssl_built & 0xffffff) != (ssl_linked & 0xffffff)) goto mismatch;
85 /** Convert a version number to a text string
87 * @note Not thread safe.
89 * @param v version to convert.
90 * @return pointer to a static buffer containing the version string.
92 char const *ssl_version_by_num(uint64_t v)
94 /* 2 (%s) + 1 (.) + 2 (%i) + 1 (.) + 2 (%i) + 1 (c) + 1 (-) + 2 (%i) + \0 */
95 static char buffer[13];
98 p += sprintf(p, "%i.%i.%i",
99 (int) ((0xff0000000 & v) >> 28),
100 (int) ((0x00ff00000 & v) >> 20),
101 (int) ((0x0000ff000 & v) >> 12));
103 if ((0x000000ff0 & v) >> 4) {
104 *p++ = (char) (0x60 + ((0x000000ff0 & v) >> 4));
107 sprintf(p, "-%i", (int) (0x00000000f & v));
112 /** Convert two openssl version numbers into a range string
114 * @note Not thread safe.
116 * @param low version to convert.
117 * @param high version to convert.
118 * @return pointer to a static buffer containing the version range string.
120 char const *ssl_version_range(uint64_t low, uint64_t high)
122 /* 12 (version) + 3 ( - ) + 12 (version) */
123 static char buffer[28];
126 p += strlcpy(p, ssl_version_by_num(low), sizeof(buffer));
127 p += strlcpy(p, " - ", sizeof(buffer) - (p - buffer));
128 strlcpy(p, ssl_version_by_num(high), sizeof(buffer) - (p - buffer));
133 /** Print the current linked version of Openssl
135 * Print the currently linked version of the OpenSSL library.
137 * @note Not thread safe.
138 * @return pointer to a static buffer containing libssl version information.
140 char const *ssl_version(void)
142 static char buffer[256];
144 uint64_t v = (uint64_t) SSLeay();
146 snprintf(buffer, sizeof(buffer), "%s 0x%.9" PRIx64 " (%s)",
147 SSLeay_version(SSLEAY_VERSION), /* Not all builds include a useful version number */
149 ssl_version_by_num((uint64_t) v));
154 int ssl_check_consistency(void) {
158 char const *ssl_version()
162 #endif /* ifdef HAVE_OPENSSL_CRYPTO_H */
165 /** Check if the application linking to the library has the correct magic number
167 * @param magic number as defined by RADIUSD_MAGIC_NUMBER
168 * @returns 0 on success, -1 on prefix mismatch, -2 on version mismatch -3 on commit mismatch.
170 int rad_check_lib_magic(uint64_t magic)
172 if (MAGIC_PREFIX(magic) != MAGIC_PREFIX(libmagic)) {
173 ERROR("Application and libfreeradius-server magic number (prefix) mismatch."
174 " application: %x library: %x",
175 MAGIC_PREFIX(magic), MAGIC_PREFIX(libmagic));
179 if (MAGIC_VERSION(magic) != MAGIC_VERSION(libmagic)) {
180 ERROR("Application and libfreeradius-server magic number (version) mismatch."
181 " application: %lx library: %lx",
182 (unsigned long) MAGIC_VERSION(magic), (unsigned long) MAGIC_VERSION(libmagic));
186 if (MAGIC_COMMIT(magic) != MAGIC_COMMIT(libmagic)) {
187 ERROR("Application and libfreeradius-server magic number (commit) mismatch."
188 " application: %lx library: %lx",
189 (unsigned long) MAGIC_COMMIT(magic), (unsigned long) MAGIC_COMMIT(libmagic));
197 * Display the revision number for this program
201 INFO("%s: %s", progname, radiusd_version);
203 DEBUG3("Server was built with: ");
205 #ifdef WITH_ACCOUNTING
206 DEBUG3(" accounting");
208 DEBUG3(" authentication"); /* always enabled */
210 #ifdef WITH_ASCEND_BINARY
211 DEBUG3(" ascend binary attributes");
216 #ifdef WITH_COMMAND_SOCKET
217 DEBUG3(" control-socket");
225 #ifdef WITH_DYNAMIC_CLIENTS
226 DEBUG3(" dynamic clients");
235 DEBUG3(" regex-pcre");
238 DEBUG3(" regex-posix");
242 #ifdef WITH_SESSION_MGMT
243 DEBUG3(" session-management");
264 DEBUG3(" developer");
267 DEBUG3("Server core libs:");
268 DEBUG3(" talloc : %i.%i.*", talloc_version_major(), talloc_version_minor());
269 DEBUG3(" ssl : %s", ssl_version());
271 DEBUG3("Library magic number:");
272 DEBUG3(" 0x%llx", (unsigned long long) libmagic);
274 DEBUG3("Endianess:");
275 #if defined(LITTLE_ENDIAN)
277 #elif defined(BIG_ENDIAN)
283 INFO("Copyright (C) 1999-2014 The FreeRADIUS server project and contributors");
284 INFO("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A");
285 INFO("PARTICULAR PURPOSE");
286 INFO("You may redistribute copies of FreeRADIUS under the terms of the");
287 INFO("GNU General Public License");
288 INFO("For more information about these matters, see the file named COPYRIGHT");