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;
31 char const *radiusd_version_short = RADIUSD_VERSION_STRING;
33 #ifdef HAVE_OPENSSL_CRYPTO_H
34 # include <openssl/crypto.h>
35 # include <openssl/opensslv.h>
37 static long ssl_built = OPENSSL_VERSION_NUMBER;
39 /** Check built and linked versions of OpenSSL match
41 * OpenSSL version number consists of:
42 * MNNFFPPS: major minor fix patch status
44 * Where status >= 0 && < 10 means beta, and status 10 means release.
46 * Startup check for whether the linked version of OpenSSL matches the
47 * version the server was built against.
49 * @return 0 if ok, else -1
51 int ssl_check_consistency(void)
55 ssl_linked = SSLeay();
58 * Status mismatch always triggers error.
60 if ((ssl_linked & 0x0000000f) != (ssl_built & 0x0000000f)) {
62 ERROR("libssl version mismatch. built: %lx linked: %lx",
63 (unsigned long) ssl_built,
64 (unsigned long) ssl_linked);
70 * Use the OpenSSH approach and relax fix checks after version
71 * 1.0.0 and only allow moving backwards within a patch
74 if (ssl_built & 0xf0000000) {
75 if ((ssl_built & 0xfffff000) != (ssl_linked & 0xfffff000) ||
76 (ssl_built & 0x00000ff0) > (ssl_linked & 0x00000ff0)) goto mismatch;
78 * Before 1.0.0 we require the same major minor and fix version
79 * and ignore the patch number.
81 } else if ((ssl_built & 0xfffff000) != (ssl_linked & 0xfffff000)) goto mismatch;
86 /** Convert a version number to a text string
88 * @note Not thread safe.
90 * @param v version to convert.
91 * @return pointer to a static buffer containing the version string.
93 char const *ssl_version_by_num(uint32_t v)
95 /* 2 (%s) + 1 (.) + 2 (%i) + 1 (.) + 2 (%i) + 1 (c) + 8 (%s) + \0 */
96 static char buffer[18];
99 p += sprintf(p, "%u.%u.%u",
100 (0xf0000000 & v) >> 28,
101 (0x0ff00000 & v) >> 20,
102 (0x000ff000 & v) >> 12);
104 if ((0x00000ff0 & v) >> 4) {
105 *p++ = (char) (0x60 + ((0x00000ff0 & v) >> 4));
113 if ((0x0000000f & v) == 0) {
118 } else if ((0x0000000f & v) <= 14) {
119 sprintf(p, "beta %u", 0x0000000f & v);
121 strcpy(p, "release");
127 /** Return the linked SSL version number as a string
129 * @return pointer to a static buffer containing the version string.
131 char const *ssl_version_num(void)
135 ssl_linked = SSLeay();
136 return ssl_version_by_num((uint32_t)ssl_linked);
139 /** Convert two openssl version numbers into a range string
141 * @note Not thread safe.
143 * @param low version to convert.
144 * @param high version to convert.
145 * @return pointer to a static buffer containing the version range string.
147 char const *ssl_version_range(uint32_t low, uint32_t high)
149 /* 12 (version) + 3 ( - ) + 12 (version) */
150 static char buffer[28];
153 p += strlcpy(p, ssl_version_by_num(low), sizeof(buffer));
154 p += strlcpy(p, " - ", sizeof(buffer) - (p - buffer));
155 strlcpy(p, ssl_version_by_num(high), sizeof(buffer) - (p - buffer));
160 /** Print the current linked version of Openssl
162 * Print the currently linked version of the OpenSSL library.
164 * @note Not thread safe.
165 * @return pointer to a static buffer containing libssl version information.
167 char const *ssl_version(void)
169 static char buffer[256];
171 uint32_t v = SSLeay();
173 snprintf(buffer, sizeof(buffer), "%s 0x%.8x (%s)",
174 SSLeay_version(SSLEAY_VERSION), /* Not all builds include a useful version number */
176 ssl_version_by_num(v));
181 int ssl_check_consistency(void) {
185 char const *ssl_version_num(void)
190 char const *ssl_version()
194 #endif /* ifdef HAVE_OPENSSL_CRYPTO_H */
196 /** Check if the application linking to the library has the correct magic number
198 * @param magic number as defined by RADIUSD_MAGIC_NUMBER
199 * @returns 0 on success, -1 on prefix mismatch, -2 on version mismatch -3 on commit mismatch.
201 int rad_check_lib_magic(uint64_t magic)
203 if (MAGIC_PREFIX(magic) != MAGIC_PREFIX(libmagic)) {
204 ERROR("Application and libfreeradius-server magic number (prefix) mismatch."
205 " application: %x library: %x",
206 MAGIC_PREFIX(magic), MAGIC_PREFIX(libmagic));
210 if (MAGIC_VERSION(magic) != MAGIC_VERSION(libmagic)) {
211 ERROR("Application and libfreeradius-server magic number (version) mismatch."
212 " application: %lx library: %lx",
213 (unsigned long) MAGIC_VERSION(magic), (unsigned long) MAGIC_VERSION(libmagic));
217 if (MAGIC_COMMIT(magic) != MAGIC_COMMIT(libmagic)) {
218 ERROR("Application and libfreeradius-server magic number (commit) mismatch."
219 " application: %lx library: %lx",
220 (unsigned long) MAGIC_COMMIT(magic), (unsigned long) MAGIC_COMMIT(libmagic));
227 /** Add a feature flag to the main configuration
229 * Add a feature flag (yes/no) to the 'feature' subsection
230 * off the main config.
232 * This allows the user to create configurations that work with
233 * across multiple environments.
235 * @param cs to add feature pair to.
236 * @param name of feature.
237 * @param enabled Whether the feature is present/enabled.
238 * @return 0 on success else -1.
240 int version_add_feature(CONF_SECTION *cs, char const *name, bool enabled)
244 if (!cf_pair_find(cs, name)) {
247 cp = cf_pair_alloc(cs, name, enabled ? "yes" : "no",
248 T_OP_SET, T_BARE_WORD, T_BARE_WORD);
256 /** Add a library/server version pair to the main configuration
258 * Add a version number to the 'version' subsection off the main
261 * Because of the optimisations in the configuration parser, these
262 * may be checked using regular expressions without a performance
265 * The version pairs are there primarily to work around defects
266 * in libraries or the server.
268 * @param cs to add feature pair to.
269 * @param name of library or feature.
270 * @param version Humanly readable version text.
271 * @return 0 on success else -1.
273 int version_add_number(CONF_SECTION *cs, char const *name, char const *version)
279 old = cf_pair_find(cs, name);
283 cp = cf_pair_alloc(cs, name, version, T_OP_SET, T_BARE_WORD, T_SINGLE_QUOTED_STRING);
288 WARN("Replacing user version.%s (%s) with %s", name, cf_pair_value(old), version);
290 cf_pair_replace(cs, old, version);
297 /** Initialise core feature flags
299 * @param cs Where to add the CONF_PAIRS, if null pairs will be added
300 * to the 'feature' section of the main config.
302 void version_init_features(CONF_SECTION *cs)
304 version_add_feature(cs, "accounting",
305 #ifdef WITH_ACCOUNTING
312 version_add_feature(cs, "authentication", true);
314 version_add_feature(cs, "ascend-binary-attributes",
315 #ifdef WITH_ASCEND_BINARY
322 version_add_feature(cs, "coa",
331 version_add_feature(cs, "control-socket",
332 #ifdef WITH_COMMAND_SOCKET
340 version_add_feature(cs, "detail",
348 version_add_feature(cs, "dhcp",
356 version_add_feature(cs, "dynamic-clients",
357 #ifdef WITH_DYNAMIC_CLIENTS
364 version_add_feature(cs, "osfc2",
372 version_add_feature(cs, "proxy",
380 version_add_feature(cs, "regex-pcre",
388 #if !defined(HAVE_PCRE) && defined(HAVE_REGEX)
389 version_add_feature(cs, "regex-posix", true);
390 version_add_feature(cs, "regex-posix-extended",
391 # ifdef HAVE_REG_EXTENDED
398 version_add_feature(cs, "regex-posix", false);
399 version_add_feature(cs, "regex-posix-extended", false);
402 version_add_feature(cs, "session-management",
403 #ifdef WITH_SESSION_MGMT
410 version_add_feature(cs, "stats",
418 version_add_feature(cs, "tcp",
426 version_add_feature(cs, "threads",
434 version_add_feature(cs, "tls",
442 version_add_feature(cs, "unlang",
450 version_add_feature(cs, "vmps",
458 version_add_feature(cs, "developer",
467 /** Initialise core version flags
469 * @param cs Where to add the CONF_PAIRS, if null pairs will be added
470 * to the 'version' section of the main config.
472 void version_init_numbers(CONF_SECTION *cs)
476 version_add_number(cs, "freeradius-server", radiusd_version_short);
478 snprintf(buffer, sizeof(buffer), "%i.%i.*", talloc_version_major(), talloc_version_minor());
479 version_add_number(cs, "talloc", buffer);
481 version_add_number(cs, "ssl", ssl_version_num());
483 #if defined(HAVE_REGEX) && defined(HAVE_PCRE)
484 version_add_number(cs, "pcre", pcre_version());
488 static char const *spaces = " "; /* 40 */
491 * Display the revision number for this program
493 void version_print(void)
495 CONF_SECTION *features, *versions;
499 if (DEBUG_ENABLED2) {
502 MEM(features = cf_section_alloc(NULL, "feature", NULL));
503 version_init_features(features);
505 MEM(versions = cf_section_alloc(NULL, "version", NULL));
506 version_init_numbers(versions);
508 DEBUG3("Server was built with: ");
510 for (ci = cf_item_find_next(features, NULL);
512 ci = cf_item_find_next(features, ci)) {
513 len = talloc_array_length(cf_pair_attr(cf_item_to_pair(ci)));
514 if (max < len) max = len;
517 for (ci = cf_item_find_next(versions, NULL);
519 ci = cf_item_find_next(versions, ci)) {
520 len = talloc_array_length(cf_pair_attr(cf_item_to_pair(ci)));
521 if (max < len) max = len;
525 for (ci = cf_item_find_next(features, NULL);
527 ci = cf_item_find_next(features, ci)) {
530 cp = cf_item_to_pair(ci);
531 attr = cf_pair_attr(cp);
533 DEBUG3(" %s%.*s : %s", attr,
534 (int)(max - talloc_array_length(attr)), spaces, cf_pair_value(cp));
537 talloc_free(features);
539 DEBUG3("Server core libs:");
541 for (ci = cf_item_find_next(versions, NULL);
543 ci = cf_item_find_next(versions, ci)) {
546 cp = cf_item_to_pair(ci);
547 attr = cf_pair_attr(cp);
549 DEBUG3(" %s%.*s : %s", attr,
550 (int)(max - talloc_array_length(attr)), spaces, cf_pair_value(cp));
553 talloc_free(versions);
555 DEBUG3("Endianess:");
556 #if defined(FR_LITTLE_ENDIAN)
558 #elif defined(FR_BIG_ENDIAN)
564 DEBUG3("Compilation flags:");
565 #ifdef BUILT_WITH_CPPFLAGS
566 DEBUG3(" cppflags : " BUILT_WITH_CPPFLAGS);
568 #ifdef BUILT_WITH_CFLAGS
569 DEBUG3(" cflags : " BUILT_WITH_CFLAGS);
571 #ifdef BUILT_WITH_LDFLAGS
572 DEBUG3(" ldflags : " BUILT_WITH_LDFLAGS);
574 #ifdef BUILT_WITH_LIBS
575 DEBUG3(" libs : " BUILT_WITH_LIBS);
578 INFO("Copyright (C) 1999-2015 The FreeRADIUS server project and contributors");
579 INFO("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A");
580 INFO("PARTICULAR PURPOSE");
581 INFO("You may redistribute copies of FreeRADIUS under the terms of the");
582 INFO("GNU General Public License");
583 INFO("For more information about these matters, see the file named COPYRIGHT");