Add version consistency checks between applications, libfreeradius-radius, libfreerad...
[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_version(void)
46 {
47         long ssl_linked;
48
49         ssl_linked = SSLeay();
50
51         if (ssl_linked != ssl_built) {
52                 ERROR("libssl version mismatch."
53                        "  Built with: %lx  Linked: %lx",
54                        (unsigned long) ssl_built,
55                        (unsigned long) ssl_linked);
56
57                 return -1;
58         };
59
60         return 0;
61 }
62
63 /** Print the current linked version of Openssl
64  *
65  * Print the currently linked version of the OpenSSL library.
66  */
67 char const *ssl_version(void)
68 {
69         return SSLeay_version(SSLEAY_VERSION);
70 }
71 #  else
72 int ssl_check_version(void) {
73         return 0;
74 }
75
76 char const *ssl_version()
77 {
78         return "not linked";
79 }
80 #endif /* ifdef HAVE_OPENSSL_CRYPTO_H */
81
82
83 /** Check if the application linking to the library has the correct magic number
84  *
85  * @param magic number as defined by RADIUSD_MAGIC_NUMBER
86  * @returns 0 on success, -1 on prefix mismatch, -2 on version mismatch -3 on commit mismatch.
87  */
88 int rad_check_lib_magic(uint64_t magic)
89 {
90         if (MAGIC_PREFIX(magic) != MAGIC_PREFIX(libmagic)) {
91                 ERROR("Application and libfreeradius-server magic number (prefix) mismatch."
92                       "  application: %x library: %x",
93                       MAGIC_PREFIX(magic), MAGIC_PREFIX(libmagic));
94                 return -1;
95         }
96
97         if (MAGIC_VERSION(magic) != MAGIC_VERSION(libmagic)) {
98                 ERROR("Application and libfreeradius-server magic number (version) mismatch."
99                       "  application: %lx library: %lx",
100                       (unsigned long) MAGIC_VERSION(magic), (unsigned long) MAGIC_VERSION(libmagic));
101                 return -2;
102         }
103
104         if (MAGIC_COMMIT(magic) != MAGIC_COMMIT(libmagic)) {
105                 ERROR("Application and libfreeradius-server magic number (commit) mismatch."
106                       "  application: %lx library: %lx",
107                       (unsigned long) MAGIC_COMMIT(magic), (unsigned long) MAGIC_COMMIT(libmagic));
108                 return -3;
109         }
110
111         return 0;
112 }
113
114 /*
115  *      Display the revision number for this program
116  */
117 void version(void)
118 {
119         INFO("%s: %s", progname, radiusd_version);
120
121         DEBUG3("Server was built with: ");
122
123 #ifdef WITH_ACCOUNTING
124         DEBUG3("  accounting");
125 #endif
126         DEBUG3("  authentication"); /* always enabled */
127
128 #ifdef WITH_ASCEND_BINARY
129         DEBUG3("  ascend binary attributes");
130 #endif
131 #ifdef WITH_COA
132         DEBUG3("  coa");
133 #endif
134 #ifdef WITH_COMMAND_SOCKET
135         DEBUG3("  control-socket");
136 #endif
137 #ifdef WITH_DETAIL
138         DEBUG3("  detail");
139 #endif
140 #ifdef WITH_DHCP
141         DEBUG3("  dhcp");
142 #endif
143 #ifdef WITH_DYNAMIC_CLIENTS
144         DEBUG3("  dynamic clients");
145 #endif
146 #ifdef OSFC2
147         DEBUG3("  OSFC2");
148 #endif
149 #ifdef WITH_PROXY
150         DEBUG3("  proxy");
151 #endif
152 #ifdef HAVE_PCREPOSIX_H
153         DEBUG3("  regex-pcre");
154 #else
155 #ifdef HAVE_REGEX_H
156         DEBUG3("  regex-posix");
157 #endif
158 #endif
159
160 #ifdef WITH_SESSION_MGMT
161         DEBUG3("  session-management");
162 #endif
163 #ifdef WITH_STATS
164         DEBUG3("  stats");
165 #endif
166 #ifdef WITH_TCP
167         DEBUG3("  tcp");
168 #endif
169 #ifdef WITH_THREADS
170         DEBUG3("  threads");
171 #endif
172 #ifdef WITH_TLS
173         DEBUG3("  tls");
174 #endif
175 #ifdef WITH_UNLANG
176         DEBUG3("  unlang");
177 #endif
178 #ifdef WITH_VMPS
179         DEBUG3("  vmps");
180 #endif
181
182         DEBUG3("Server core libs:");
183         DEBUG3("  talloc : %i.%i.*", talloc_version_major(), talloc_version_minor());
184         DEBUG3("  ssl    : %s", ssl_version());
185
186         DEBUG3("Library magic number:");
187         DEBUG3("  0x%llx", (unsigned long long) libmagic);
188
189         INFO("Copyright (C) 1999-2014 The FreeRADIUS server project and contributors");
190         INFO("There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A");
191         INFO("PARTICULAR PURPOSE");
192         INFO("You may redistribute copies of FreeRADIUS under the terms of the");
193         INFO("GNU General Public License");
194         INFO("For more information about these matters, see the file named COPYRIGHT");
195
196         fflush(NULL);
197 }
198