util.h revision db78f4c750943fcd4b60bca5f3fdfd6cc5d3d4f8
/*
Authors:
Simo Sorce <ssorce@redhat.com>
Copyright (C) 2009 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSSD_UTIL_H__
#define __SSSD_UTIL_H__
#include "config.h"
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <errno.h>
#include <libintl.h>
#include <limits.h>
#include <locale.h>
#include <time.h>
#include <pcre.h>
#include <talloc.h>
#include <tevent.h>
#include <ldb.h>
#include <dhash.h>
#include "util/atomic_io.h"
#include "util/util_errors.h"
#include "util/util_safealign.h"
#define ENUM_INDICATOR "*"
#define CLEAR_MC_FLAG "clear_mc_flag"
extern const char *debug_prg_name;
extern int debug_level;
extern int debug_timestamps;
extern int debug_microseconds;
extern int debug_to_file;
extern const char *debug_log_file;
int debug_get_level(int old_level);
int debug_convert_old_level(int old_level);
#define SSSDBG_INVALID -1
#define SSSDBG_UNRESOLVED 0
#define SSSDBG_DEFAULT SSSDBG_FATAL_FAILURE
#define SSSDBG_TIMESTAMP_UNRESOLVED -1
#define SSSDBG_TIMESTAMP_DEFAULT 1
#define SSSDBG_MICROSECONDS_UNRESOLVED -1
#define SSSDBG_MICROSECONDS_DEFAULT 0
#define SSSD_DEBUG_OPTS \
_("Debug level"), NULL}, \
_("Send the debug output to files instead of stderr"), NULL }, \
_("Add debug timestamps"), NULL}, \
_("Show timestamps with microseconds"), NULL},
/** \def DEBUG(level, body)
\brief macro to generate debug messages
\param level the debug level, please use one of the SSSDBG_* macros
Old format:
- 1 is for critical errors users may find it difficult to understand but
are still quite clear
- 2-4 is for stuff developers are interested in in general, but
shouldn't fill the screen with useless low level verbose stuff
- 5-6 is for errors you may want to track, but only if you explicitly
looking for additional clues
- 7-10 is for informational stuff
\param body the debug message you want to send, should end with \n
*/
if (DEBUG_IS_SET(__debug_macro_newlevel)) { \
if (debug_timestamps) { \
struct timeval __debug_macro_tv; \
struct tm *__debug_macro_tm; \
char __debug_macro_datetime[20]; \
int __debug_macro_year; \
/* get date time without year */ \
if (debug_microseconds) { \
debug_fn("(%s:%.6d %d) [%s] [%s] (%#.4x): ", \
} else { \
debug_fn("(%s %d) [%s] [%s] (%#.4x): ", \
} \
} else { \
debug_fn("[%s] [%s] (%#.4x): ", \
} \
} \
} while(0)
/** \def DEBUG_MSG(level, function, message)
\brief macro to generate debug messages with message from variable
\param level the debug level, please use one of the SSSDBG_* macros
\param function name of the function where DEBUG_MSG is called
\param message message to be send (should not end with \n)
*/
if (DEBUG_IS_SET(__debug_macro_newlevel)) { \
if (debug_timestamps) { \
struct timeval __debug_macro_tv; \
struct tm *__debug_macro_tm; \
char __debug_macro_datetime[20]; \
int __debug_macro_year; \
/* get date time without year */ \
if (debug_microseconds) { \
debug_fn("(%s:%.6d %d) [%s] [%s] (%#.4x): %s\n", \
} else { \
debug_fn("(%s %d) [%s] [%s] (%#.4x): %s\n", \
message); \
} \
} else { \
debug_fn("[%s] [%s] (%#.4x): %s\n", \
} \
} \
} while(0)
/** \def DEBUG_IS_SET(level)
\brief checks whether level (must be in new format) is set in debug_level
\param level the debug level, please use one of the SSSDBG*_ macros
*/
(debug_level == SSSDBG_UNRESOLVED && \
(level & (SSSDBG_FATAL_FAILURE | \
#define DEBUG_INIT(dbg_lvl) do { \
if (dbg_lvl != SSSDBG_INVALID) { \
} else { \
} \
\
} while (0)
#ifndef discard_const
#endif
#ifndef NULL
#define NULL 0
#endif
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
#define SSSD_MAIN_OPTS SSSD_DEBUG_OPTS
#define FLAGS_NONE 0x0000
#define FLAGS_DAEMON 0x0001
#define FLAGS_INTERACTIVE 0x0002
#define FLAGS_PID_FILE 0x0004
#ifndef talloc_zfree
#endif
#ifndef discard_const_p
#if defined(__intptr_t_defined) || defined(HAVE_INTPTR_T)
#else
#endif
#endif
/* TODO: remove later
* These functions are available in the latest tevent and are the ones that
* should be used as tevent_req is rightfully opaque there */
#ifndef tevent_req_data
#define tevent_req_notify_callback(req) \
do { \
} \
} while(0)
/* noop */
#define tevent_loop_allow_nesting(x)
#endif
#define TEVENT_REQ_RETURN_ON_ERROR(req) do { \
enum tevent_req_state TRROEstate; \
\
if (TRROEstate == TEVENT_REQ_USER_ERROR) { \
return TRROEerr; \
} \
return ERR_INTERNAL; \
} \
} while (0)
#include "util/dlinklist.h"
/* From debug.c */
int open_debug_file(void);
int rotate_debug_files(void);
void talloc_log_fn(const char *msg);
/* From sss_log.c */
#define SSS_LOG_EMERG 0 /* system is unusable */
/* from server.c */
struct main_context {
struct tevent_context *event_ctx;
struct confdb_ctx *confdb_ctx;
};
int die_if_parent_died(void);
const char *conf_entry,
struct main_context **main_ctx);
/* from signal.c */
#include <signal.h>
void CatchChild(void);
void CatchChildLeaveStatus(void);
/* from memory.c */
typedef int (void_destructor_fn_t)(void *);
struct mem_holder {
void *mem;
};
void *ptr,
int password_destructor(void *memctx);
/* from usertools.c */
struct sss_names_ctx {
char *re_pattern;
char *fq_fmt;
};
/* initialize sss_names_ctx directly from arguments */
const char *re_pattern,
const char *fq_fmt,
struct sss_names_ctx **out);
/* initialize sss_names_ctx from domain configuration */
struct confdb_ctx *cdb,
const char *domain,
struct sss_names_ctx **out);
struct sss_names_ctx *snctx,
char *
bool case_sensitive);
bool case_sensitive, const char ***_cased);
/* from backup-file.c */
/* from check_and_open.c */
enum check_file_type {
};
/* check_file()
* file type. This function can be used to determine if a file is a
* symlink.
* Warning: use of this function implies a potential race condition
* Opening a file before or after checking it does NOT guarantee that
* it is still the same file. Additional checks should be performed
* on the caller_stat_buf to ensure that it has the same device and
* inode to minimize impact. Permission changes may have occurred,
* however.
*/
/* check_fd()
* is of a certain file type. This function CANNOT detect symlinks,
* as the file is already open and symlinks have been traversed. This
* is the safer way to perform file checks and should be preferred
* over check_file for nearly all situations.
*/
struct stat *caller_stat_buf);
/* check_and_open_readonly()
* Utility function to open a file and verify that it has certain
* permissions and is of a certain file type. This function wraps
* check_fd(), and is considered race-condition safe.
*/
enum check_file_type type);
/* from util.c */
char **parse_args(const char *str);
unsigned long count,
hash_table_t **tbl);
unsigned long count,
hash_table_t **tbl,
unsigned int directory_bits,
unsigned int segment_bits,
unsigned long min_load_factor,
unsigned long max_load_factor,
void *delete_private_data);
/* Copy a NULL-terminated string list
* Returns NULL on out of memory error or invalid input
*/
/* Take two string lists (terminated on a NULL char*)
* and return up to three arrays of strings based on
* shared ownership.
*
* Pass NULL to any return type you don't care about
*/
char **string1,
char **string2,
char ***string1_only,
char ***string2_only,
char ***both_strings);
/* Sanitize an input string (e.g. a username) for use in
* Returns a newly-constructed string attached to mem_ctx
* It will fail only on an out of memory condition, where it
* will return ENOMEM.
*/
const char *input,
char **sanitized);
char *
/* This function only removes first and last
* character if the first character was '['.
*
* NOTE: This means, that ipv6addr must NOT be followed
* by port number.
*/
remove_ipv6_brackets(char *ipv6addr);
char ***list_p);
/**
* @brief Safely zero a segment of memory,
* prevents the compiler from optimizing out
*
* @param data The address of buffer to wipe
* @param s Size of the buffer
*/
/* from nscd.c */
enum nscd_db {
};
/* from sss_tc_utf8.c */
char *
uint8_t *
/* len includes terminating '\0' */
struct sized_string {
const char *str;
};
/* form domain_info.c */
bool descend);
const char *name,
bool match_any);
struct sss_domain_info *parent,
const char *name,
const char *realm,
const char *flat_name,
const char *id);
struct confdb_ctx *cdb,
const char *domain_name,
const char *db_path,
struct sss_domain_info **_domain);
/* from util_lock.c */
#include "io.h"
/* Endianness-compatibility for systems running older versions of glibc */
#ifndef le32toh
#include <byteswap.h>
/* Copied from endian.h on glibc 2.15 */
#ifdef __USE_BSD
/* Conversion interfaces. */
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define le32toh(x) (x)
# define htole32(x) (x)
# else
# define le32toh(x) __bswap_32 (x)
# define htole32(x) __bswap_32 (x)
# endif
#endif /* __USE_BSD */
#endif /* le32toh */
#ifdef HAVE_PAC_RESPONDER
#define BUILD_WITH_PAC_RESPONDER true
#else
#define BUILD_WITH_PAC_RESPONDER false
#endif
#endif /* __SSSD_UTIL_H__ */