26 RCSID(
"$Id: 0934122f6e55427387b7637585df9e33b1c5fafe $")
28 #include <freeradius-devel/util/conf.h>
29 #include <freeradius-devel/util/syserror.h>
30 #include <freeradius-devel/util/atexit.h>
31 #include <freeradius-devel/util/dict_priv.h>
52 #define DEBUG2(fmt, ...) if (fr_log_fp && (fr_debug_lvl > 2)) fprintf(fr_log_fp , fmt "\n", ## __VA_ARGS__)
53 #define DEBUG(fmt, ...) if (fr_log_fp && (fr_debug_lvl > 1)) fprintf(fr_log_fp , fmt "\n", ## __VA_ARGS__)
54 #define INFO(fmt, ...) if (fr_log_fp && (fr_debug_lvl > 0)) fprintf(fr_log_fp , fmt "\n", ## __VA_ARGS__)
59 fprintf(stderr,
"usage: radict [OPTS] <attribute> [attribute...]\n");
60 fprintf(stderr,
" -E Export dictionary definitions.\n");
61 fprintf(stderr,
" -V Write out all attribute values.\n");
62 fprintf(stderr,
" -D <dictdir> Set main dictionary directory (defaults to " DICTDIR
").\n");
63 fprintf(stderr,
" -p <protocol> Set protocol by name\n");
64 fprintf(stderr,
" -x Debugging mode.\n");
65 fprintf(stderr,
" -c Print out in CSV format.\n");
66 fprintf(stderr,
" -H Show the headers of each field.\n");
67 fprintf(stderr,
"\n");
68 fprintf(stderr,
"Very simple interface to extract attribute definitions from FreeRADIUS dictionaries\n");
71 static int load_dicts(
char const *dict_dir,
char const *protocol)
76 INFO(
"Reading directory %s", dict_dir);
78 dir = opendir(dict_dir);
84 while ((dp = readdir(dir)) != NULL) {
85 struct stat stat_buff;
88 if (dp->d_name[0] ==
'.')
continue;
93 if (protocol && (strcmp(dp->d_name, protocol) != 0))
continue;
98 if (strcmp(dp->d_name,
"freeradius") == 0)
continue;
100 file_str = talloc_asprintf(NULL,
"%s/%s", dict_dir, dp->d_name);
102 if (stat(file_str, &stat_buff) == -1) {
113 if ((stat_buff.st_mode & S_IFMT) == S_IFDIR) {
115 struct stat dict_stat_buff;
118 dict_file = talloc_asprintf(NULL,
"%s/dictionary", file_str);
119 ret = stat(dict_file, &dict_stat_buff);
132 INFO(
"Loading dictionary: %s/dictionary", file_str);
170 printf(
"%s,%s,%s,%d,%s,%s\n",
181 printf(
"%s\t%s\t%s\t%d\t%s\t%s\n",
204 str =
fr_asprintf(NULL,
"%s,%s,%s,%d,%s,%s,%s,%pV",
217 str =
fr_asprintf(NULL,
"%s\t%s\t%s\t%d\t%s\t%s\t%s\t%pV",
248 if (!da->flags.is_root) {
249 if (low && ((uintptr_t)da < *low)) {
250 *low = (uintptr_t)da;
252 if (high && ((uintptr_t)da > *high)) {
253 *high = (uintptr_t)da;
259 if (
count) (*count)++;
266 len = talloc_array_length(children);
267 for (i = 0; i < len; i++) {
268 for (p = children[i]; p; p = p->next) {
278 if (low) *low = UINTPTR_MAX;
288 int main(
int argc,
char *argv[])
290 char const *dict_dir = DICTDIR;
295 bool file_export =
false;
296 char const *protocol = NULL;
314 talloc_set_log_stderr();
318 while ((c = getopt(argc, argv,
"cfED:p:VxhH")) != -1)
switch (c) {
371 fr_perror(
"radict - Global context init failed");
379 fr_perror(
"radict - Loading internal dictionary failed");
388 fr_perror(
"radict - Loading dictionaries failed");
394 fr_perror(
"radict - No dictionaries loaded");
401 printf(
"Dictionary,OID,Attribute,ID,Type,Flags\n");
406 printf(
"Dictionary\tOID\tAttribute\tID\tType\tFlags\n");
429 DEBUG2(
"Memory allocd %zu (bytes)", talloc_total_size(*dict_p));
430 DEBUG2(
"Memory spread %zu (bytes)", (
size_t) (high - low));
477 return found ? ret : 64;
int fr_atexit_global_setup(void)
Setup the atexit handler, should be called at the start of a program's execution.
int fr_atexit_global_trigger_all(void)
Cause all global free triggers to fire.
int fr_fault_setup(TALLOC_CTX *ctx, char const *cmd, char const *program)
Registers signal handlers to execute panic_action on fatal signal.
#define fr_exit(_x)
Exit, producing a log message in debug builds.
fr_dict_attr_t const * fr_dict_attr_by_oid(fr_dict_attr_err_t *err, fr_dict_attr_t const *parent, char const *oid))
Resolve an attribute using an OID string.
int fr_dict_internal_afrom_file(fr_dict_t **out, char const *internal_name, char const *dependent)
(Re-)Initialize the special internal dictionary
int fr_dict_protocol_afrom_file(fr_dict_t **out, char const *proto_name, char const *proto_dir, char const *dependent)
(Re)-initialize a protocol dictionary
fr_dict_attr_t const * fr_dict_root(fr_dict_t const *dict)
Return the root attribute of a dictionary.
fr_value_box_t const * value
Enum value (what name maps to).
int fr_dict_free(fr_dict_t **dict, char const *dependent)
Decrement the reference count on a previously loaded dictionary.
fr_dict_t const * fr_dict_by_da(fr_dict_attr_t const *da)
Attempt to locate the protocol dictionary containing an attribute.
@ FR_DICT_ATTR_EXT_ENUMV
Enumeration values.
void fr_dict_export(fr_dict_t const *dict)
Export in the standard form: ATTRIBUTE name oid flags.
char const * name
Enum name.
fr_dict_gctx_t * fr_dict_global_ctx_init(TALLOC_CTX *ctx, bool free_at_exit, char const *dict_dir)
Initialise the global protocol hashes.
Value of an enumerated attribute.
static void * fr_dict_attr_ext(fr_dict_attr_t const *da, fr_dict_attr_ext_t ext)
fr_hash_table_t * value_by_name
Lookup an enumeration value by name.
Attribute extension - Holds enumeration values.
static fr_dict_attr_t const ** dict_attr_children(fr_dict_attr_t const *da)
void * fr_hash_table_iter_init(fr_hash_table_t *ht, fr_hash_iter_t *iter)
Initialise an iterator.
void * fr_hash_table_iter_next(fr_hash_table_t *ht, fr_hash_iter_t *iter)
Iterate over entries in a hash table.
Stores the state of the current iteration operation.
ssize_t fr_dict_attr_flags_print(fr_sbuff_t *out, fr_dict_t const *dict, fr_type_t type, fr_dict_attr_flags_t const *flags)
ssize_t fr_dict_attr_oid_print(fr_sbuff_t *out, fr_dict_attr_t const *ancestor, fr_dict_attr_t const *da, bool numeric)
int strcasecmp(char *s1, char *s2)
char * fr_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Special version of asprintf which implements custom format specifiers.
static TALLOC_CTX * autofree
int main(int argc, char *argv[])
static fr_dict_t ** dict_end
static int load_dicts(char const *dict_dir, char const *protocol)
static void raddict_export(uint64_t *count, uintptr_t *low, uintptr_t *high, fr_dict_t *dict)
static fr_dict_t * dicts[255]
static bool print_headers
static void _raddict_export(fr_dict_t const *dict, uint64_t *count, uintptr_t *low, uintptr_t *high, fr_dict_attr_t const *da, unsigned int lvl)
static void da_print_info_td(fr_dict_t const *dict, fr_dict_attr_t const *da)
static radict_out_t output_format
#define fr_sbuff_start(_sbuff_or_marker)
#define FR_SBUFF_OUT(_start, _len_or_end)
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
#define FR_DICTIONARY_FILE
#define FR_DICTIONARY_INTERNAL_DIR
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
void fr_strerror_clear(void)
Clears all pending messages from the talloc pools.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
#define RADIUSD_MAGIC_NUMBER