util.h revision b114bcc370c8d78b5e9f43963cfa91213901c3be
81d182b21020b815887e9057959228546cf61b6bChristian Maeder Simo Sorce <ssorce@redhat.com>
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu Copyright (C) 2009 Red Hat
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maeder This program is free software; you can redistribute it and/or modify
967e5f3c25249c779575864692935627004d3f9eChristian Maeder it under the terms of the GNU General Public License as published by
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian Maeder the Free Software Foundation; either version 3 of the License, or
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder (at your option) any later version.
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder This program is distributed in the hope that it will be useful,
967e5f3c25249c779575864692935627004d3f9eChristian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
967e5f3c25249c779575864692935627004d3f9eChristian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
967e5f3c25249c779575864692935627004d3f9eChristian Maeder GNU General Public License for more details.
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder You should have received a copy of the GNU General Public License
7221c71b38c871ce66eee4537cb681d468308dfbChristian Maeder along with this program. If not, see <http://www.gnu.org/licenses/>.
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder#define SSS_ATTRIBUTE_PRINTF(a1, a2) __attribute__ ((format (printf, a1, a2)))
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederextern const char *debug_prg_name;
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederextern const char *debug_log_file;
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder const char *format, ...) SSS_ATTRIBUTE_PRINTF(5,6);
7a879b08ae0ca30006f9be887a73212b07f10204Christian Maedererrno_t set_debug_file_from_fd(const int fd);
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_FATAL_FAILURE 0x0010 /* level 0 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_CRIT_FAILURE 0x0020 /* level 1 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_OP_FAILURE 0x0040 /* level 2 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_MINOR_FAILURE 0x0080 /* level 3 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_CONF_SETTINGS 0x0100 /* level 4 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_FUNC_DATA 0x0200 /* level 5 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_TRACE_FUNC 0x0400 /* level 6 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_TRACE_LIBS 0x1000 /* level 7 */
a89389521ddf76109168a0b339031575aafbd512Christian Maeder#define SSSDBG_TRACE_INTERNAL 0x2000 /* level 8 */
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder#define SSSDBG_TRACE_ALL 0x4000 /* level 9 */
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder#define SSSDBG_IMPORTANT_INFO SSSDBG_OP_FAILURE
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder#define SSSDBG_MASK_ALL 0xFFF0 /* enable all debug levels */
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder {"debug-to-files", 'f', POPT_ARG_NONE, &debug_to_file, 0, \
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder _("Send the debug output to files instead of stderr"), NULL }, \
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder {"debug-to-stderr", 0, POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN, &debug_to_stderr, 0, \
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder _("Send the debug output to stderr directly."), NULL }, \
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder {"debug-timestamps", 0, POPT_ARG_INT, &debug_timestamps, 0, \
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder {"debug-microseconds", 0, POPT_ARG_INT, &debug_microseconds, 0, \
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder _("Show timestamps with microseconds"), NULL},
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder/** \def DEBUG(level, format, ...)
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maeder \brief macro to generate debug messages
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder \param level the debug level, please use one of the SSSDBG_* macros
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder \param format the debug message format string, should result in a
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maeder newline-terminated message
d4146229cf85928342dfd25ec8b579a7feb0d381Christian Maeder \param ... the debug message format arguments
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder debug_fn(__FILE__, __LINE__, __FUNCTION__, \
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder/** \def DEBUG_IS_SET(level)
e7ce154edb906685b3fa7f6c0a764e18a4658068Christian Maeder \brief checks whether level is set in debug_level
9b30898b139ee02f97ac933b6d935ef0a4206921Christian Maeder \param level the debug level, please use one of the SSSDBG*_ macros
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder#define DEBUG_IS_SET(level) (debug_level & (level) || \
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder debug_level = debug_convert_old_level(dbg_lvl); \
0a8ea95bcf0e3f84fed0b725c049ec2a956a4a28Christian Maeder/* CLI tools shall debug to stderr even when SSSD was compiled with journald
3c8d067accf18572352351ec42ff905c7297a8a5Christian Maeder#define PRINT(fmt, ...) fprintf(stdout, gettext(fmt), ##__VA_ARGS__)
58b5ac21d1c88344246aaedab0c0bdc7b759d7c6Christian Maeder#define ERROR(fmt, ...) fprintf(stderr, gettext(fmt), ##__VA_ARGS__)
81d182b21020b815887e9057959228546cf61b6bChristian Maeder#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
4072adb8c5d2c86123e8e1c1918263968f187829Christian Maeder _("The user ID to run the server as"), NULL}, \
4072adb8c5d2c86123e8e1c1918263968f187829Christian Maeder _("The group ID to run the server as"), NULL},
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maeder#define talloc_zfree(ptr) do { talloc_free(discard_const(ptr)); ptr = NULL; } while(0)
bfa9e03532243ceb487f0384d0f6a447f1ce7670Till Mossakowski#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
967e5f3c25249c779575864692935627004d3f9eChristian Maeder# define discard_const_p(type, ptr) ((type *)((intptr_t)(ptr)))
f2ee9fc53048ea92bad79e3f5d292d83efd7f8beMihai Codescu# define discard_const_p(type, ptr) ((type *)(ptr))
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder#define TEVENT_REQ_RETURN_ON_ERROR(req) do { \
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder if (tevent_req_is_error(req, &TRROEstate, &TRROEerr)) { \
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder if (TRROEstate == TEVENT_REQ_USER_ERROR) { \
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder (id == 0 || (min && (id < min)) || (max && (id > max)))
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maedervoid ldb_debug_messages(void *context, enum ldb_debug_level level,
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maederint chown_debug_file(const char *filename, uid_t uid, gid_t gid);
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maederint open_debug_file_ex(const char *filename, FILE **filep, bool want_cloexec);
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maeder#define SSS_LOG_EMERG 0 /* system is unusable */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder#define SSS_LOG_ALERT 1 /* action must be taken immediately */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder#define SSS_LOG_CRIT 2 /* critical conditions */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder#define SSS_LOG_ERR 3 /* error conditions */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder#define SSS_LOG_WARNING 4 /* warning conditions */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder#define SSS_LOG_NOTICE 5 /* normal but significant condition */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder#define SSS_LOG_DEBUG 7 /* debug-level messages */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maedervoid sss_log(int priority, const char *format, ...) SSS_ATTRIBUTE_PRINTF(2, 3);
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maedervoid sss_log_ext(int priority, int facility, const char *format, ...) SSS_ATTRIBUTE_PRINTF(3, 4);
ad187062b0009820118c1b773a232e29b879a2faChristian Maedererrno_t server_common_rotate_logs(struct confdb_ctx *confdb,
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maederint pidfile(const char *path, const char *name);
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maederint server_setup(const char *name, int flags,
9659c509ce5e78adc51d7b02a76274eddcba9338Christian Maedervoid server_loop(struct main_context *main_ctx);
9659c509ce5e78adc51d7b02a76274eddcba9338Christian Maedervoid (*CatchSignal(int signum,void (*handler)(int )))(int);
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian Maedertypedef int (void_destructor_fn_t)(void *);
d4146229cf85928342dfd25ec8b579a7feb0d381Christian Maederchar *get_uppercase_realm(TALLOC_CTX *memctx, const char *name);
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder/* initialize sss_names_ctx directly from arguments */
588c0c022a0f4e129a89c3bc569daf6a835e182dChristian Maederint sss_names_init_from_args(TALLOC_CTX *mem_ctx,
const char *domain,
const char *default_domain,
bool case_sensitive);
const char *name);
/* from backup-file.c */
/* from util.c */
#define SSS_NO_SPECIAL \
const char * const * get_known_services(void);
unsigned long count,
unsigned long count,
unsigned int directory_bits,
unsigned int segment_bits,
unsigned long min_load_factor,
unsigned long max_load_factor,
void *delete_private_data);
char **string1,
char **string2,
char ***string1_only,
char ***string2_only,
char ***both_strings);
const char *input,
char **sanitized);
const char *input,
char **sanitized,
char **lc_sanitized);
char ***list_p);
/* from nscd.c */
enum nscd_db {
/* from sss_tc_utf8.c */
uint8_t *
struct sized_string {
const char *str;
/* from domain_info.c */
bool descend);
const char *name,
bool match_any);
const char *sid);
struct sss_domain_info*
const char* sid);
struct sss_domain_info *
const char *object_name);
const char *sd_name);
const char *name,
const char *realm,
const char *flat_name,
const char *id,
bool mpg,
bool enumerate,
const char *forest);
const char *domain_name,
const char *db_path,
char ***_dom_names,
int *_dom_names_count);
/* from util_lock.c */
#include "io.h"
#ifdef HAVE_PAC_RESPONDER
#define BUILD_WITH_PAC_RESPONDER true
#define BUILD_WITH_PAC_RESPONDER false
/* from well_known_sids.c */
const char **name);
const char **sid);
/* from string_utils.c */
const char *orig_name,
const char replace_char);
const char *orig_name,
const char replace_char);
/* from become_user.c */
struct sss_creds;
/* from sss_semanage.c */
const char *mlsrange);