2 * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file adu.h Global definitions. */
14 #include <time.h> /* time(), localtime() */
20 #include <netinet/in.h>
21 #include <arpa/inet.h>
22 #include <sys/socket.h>
23 #include <sys/un.h> /* needed by create_pf_socket */
27 #include "gcc-compat.h"
29 /** debug loglevel, gets really noisy */
31 /** still noisy, but won't fill your disk */
33 /** normal, but significant event */
35 /** unexpected event that can be handled */
37 /** unhandled error condition */
39 /** system might be unreliable */
41 /** last message before exit */
44 /** Log messages with lower priority than that will not be compiled in. */
45 #define COMPILE_TIME_LOGLEVEL 0
48 #if DEBUG > COMPILE_TIME_LOGLEVEL
49 #define DEBUG_LOG(f,...) __log(DEBUG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
51 #define DEBUG_LOG(...) do {;} while (0)
54 #if INFO > COMPILE_TIME_LOGLEVEL
55 #define INFO_LOG(f,...) __log(INFO, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
57 #define INFO_LOG(...) do {;} while (0)
60 #if NOTICE > COMPILE_TIME_LOGLEVEL
61 #define NOTICE_LOG(f,...) __log(NOTICE, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
63 #define NOTICE_LOG(...) do {;} while (0)
66 #if WARNING > COMPILE_TIME_LOGLEVEL
67 #define WARNING_LOG(f,...) __log(WARNING, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
69 #define WARNING_LOG(...) do {;} while (0)
72 #if ERROR > COMPILE_TIME_LOGLEVEL
73 #define ERROR_LOG(f,...) __log(ERROR, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
75 #define ERROR_LOG(...) do {;} while (0)
78 #if CRIT > COMPILE_TIME_LOGLEVEL
79 #define CRIT_LOG(f,...) __log(CRIT, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
81 #define CRIT_LOG(...) do {;} while (0)
84 #if EMERG > COMPILE_TIME_LOGLEVEL
85 #define EMERG_LOG(f,...) __log(EMERG, "%s: " f, __FUNCTION__, ## __VA_ARGS__)
87 #define EMERG_LOG(...)
92 * Write a log message to a dynamically allocated string.
94 * \param fmt Usual format string.
95 * \param p Result pointer.
98 #define VSPRINTF(fmt, p) \
102 p = adu_malloc(size); \
105 /* Try to print in the allocated space. */ \
107 n = vsnprintf(p, size, fmt, ap); \
109 /* If that worked, return the string. */ \
110 if (n > -1 && n < size) \
112 /* Else try again with more space. */ \
113 if (n > -1) /* glibc 2.1 */ \
114 size = n + 1; /* precisely what is needed */ \
115 else /* glibc 2.0 */ \
116 size *= 2; /* twice the old size */ \
117 p = adu_realloc(p, size); \
121 /** The columns of the directory table. */
122 enum dir_table_columns {
123 /** The name of the directory. */
125 /** The dir count number. */
127 /** The number of the parent directory. */
129 /** The number of bytes of all regular files. */
131 /** The number of all regular files. */
133 /** Number of columns in this table. */
137 /** The columns of the id table. */
138 enum user_table_columns {
139 /** The numer of the directory. */
141 /** The number of bytes of all regular files in this dir owned by this id. */
143 /** The number of files in this dir owned by this id. */
145 /** Number of columns in this table. */
149 enum uid_info_flags {
150 /** Whether this slot of the hash table is used. */
152 /** Whether this uid should be taken into account. */
153 UI_FL_ADMISSIBLE = 2,
160 struct osl_table *table;
164 struct osl_table_description *desc;
172 enum search_uid_flags {
174 CREATE_USER_TABLE = 2,
177 extern uint32_t num_uids;
178 extern struct osl_table *dir_table;
179 extern struct gengetopt_args_info conf;
182 __printf_2_3 void __log(int, const char*, ...);
183 int open_dir_table(int create);
184 void check_signals(void);
185 void close_all_tables(void);
186 char *get_uid_list_name(void);
187 void create_hash_table(unsigned bits);
188 int search_uid(uint32_t uid, enum search_uid_flags flags,
189 struct user_info **ui_ptr);
190 int for_each_admissible_user(int (*func)(struct user_info *, void *),
194 int com_select(void);
197 int com_create(void);