All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
version.c
Go to the documentation of this file.
1 /*
2  * version.c Validate application and library magic numbers.
3  *
4  * Version: $Id: f5bb64dd25f145e5b6b948aabd8de099cf4c4f16 $
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  */
22 
23 RCSID("$Id: f5bb64dd25f145e5b6b948aabd8de099cf4c4f16 $")
24 
25 #include <freeradius-devel/libradius.h>
26 
27 static uint64_t libmagic = RADIUSD_MAGIC_NUMBER;
28 
29 /** Check if the application linking to the library has the correct magic number
30  *
31  * @param magic number as defined by RADIUSD_MAGIC_NUMBER
32  * @returns
33  * - 0 on success.
34  * - -1 on prefix mismatch.
35  * - -2 on version mismatch.
36  * - -3 on commit mismatch.
37  */
38 int fr_check_lib_magic(uint64_t magic)
39 {
40  if (MAGIC_PREFIX(magic) != MAGIC_PREFIX(libmagic)) {
41  fr_strerror_printf("Application and libfreeradius-radius magic number (prefix) mismatch."
42  " application: %x library: %x",
43  MAGIC_PREFIX(magic), MAGIC_PREFIX(libmagic));
44  return -1;
45  }
46 
47  if (MAGIC_VERSION(magic) != MAGIC_VERSION(libmagic)) {
48  fr_strerror_printf("Application and libfreeradius-radius magic number (version) mismatch."
49  " application: %lx library: %lx",
50  (unsigned long) MAGIC_VERSION(magic), (unsigned long) MAGIC_VERSION(libmagic));
51  return -2;
52  }
53 
54  if (MAGIC_COMMIT(magic) != MAGIC_COMMIT(libmagic)) {
55  fr_strerror_printf("Application and libfreeradius-radius magic number (commit) mismatch."
56  " application: %lx library: %lx",
57  (unsigned long) MAGIC_COMMIT(magic), (unsigned long) MAGIC_COMMIT(libmagic));
58  return -3;
59  }
60 
61  return 0;
62 }
#define MAGIC_PREFIX(_x)
Definition: libradius.h:53
#define MAGIC_COMMIT(_x)
Definition: libradius.h:55
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
Definition: version.c:38
void fr_strerror_printf(char const *,...) CC_HINT(format(printf
#define RCSID(id)
Definition: build.h:135
#define MAGIC_VERSION(_x)
Definition: libradius.h:54
#define RADIUSD_MAGIC_NUMBER
Definition: libradius.h:51
static uint64_t libmagic
Definition: version.c:27