util.h revision 1d93029624d708119bbf803e6647a2cbb271f001
/*
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 <fcntl.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"
#include "util/sss_format.h"
#define ENUM_INDICATOR "*"
#define CLEAR_MC_FLAG "clear_mc_flag"
#else
#endif
extern const char *debug_prg_name;
extern int debug_level;
extern int debug_timestamps;
extern int debug_microseconds;
extern int debug_to_file;
extern int debug_to_stderr;
extern const char *debug_log_file;
long line,
const char *function,
int level,
int debug_convert_old_level(int old_level);
#define SSS_DOM_ENV "_SSS_DOM"
#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 }, \
_("Send the debug output to stderr directly."), NULL }, \
_("Add debug timestamps"), NULL}, \
_("Show timestamps with microseconds"), NULL},
/** \def DEBUG(level, format, ...)
\brief macro to generate debug messages
\param level the debug level, please use one of the SSSDBG_* macros
\param format the debug message format string, should result in a
newline-terminated message
\param ... the debug message format arguments
*/
int __debug_macro_level = level; \
if (DEBUG_IS_SET(__debug_macro_level)) { \
format, ##__VA_ARGS__); \
} \
} while (0)
/** \def DEBUG_IS_SET(level)
\brief checks whether level 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)
/* CLI tools shall debug to stderr even when SSSD was compiled with journald
* support
*/
#define DEBUG_CLI_INIT(dbg_lvl) do { \
DEBUG_INIT(dbg_lvl); \
debug_to_stderr = 1; \
} 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
_("The user ID to run the server as"), NULL}, \
_("The group ID to run the server as"), NULL},
#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
#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;
};
const char *conf_entry);
int die_if_parent_died(void);
const char *conf_entry,
struct main_context **main_ctx);
void orderly_shutdown(int status);
/* from signal.c */
#include <signal.h>
/* 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,
struct sss_domain_info *domains,
const char *default_domain,
char *
bool case_sensitive);
bool case_sensitive, const char ***_cased);
/* Return fully-qualified name according to the fq_fmt. The name is allocated using
* talloc on top of mem_ctx
*/
char *
/* Return fully-qualified name according to the fq_fmt. The name is allocated using
* talloc on top of mem_ctx. In contrast to sss_tc_fqname() sss_tc_fqname2()
* expects the domain and flat domain name as separate arguments.
*/
char *
const char *dom_name, const char *flat_dom_name,
const char *name);
/* Return fully-qualified name formatted according to the fq_fmt. The buffer in "str" is
* "size" bytes long. Returns the number of bytes written on success or a negative
* value of failure.
*
* Pass a zero size to calculate the length that would be needed by the fully-qualified
* name.
*/
int
/* Subdomains use fully qualified names in the cache while primary domains use
* just the name. Return either of these for a specified domain or subdomain
*/
char *
struct sss_domain_info *dom);
/* from backup-file.c */
/* 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.
*/
/* from util.c */
#define SSS_NO_LINKLOCAL 0x01
#define SSS_NO_LOOPBACK 0x02
#define SSS_NO_MULTICAST 0x04
#define SSS_NO_BROADCAST 0x08
#define SSS_NO_SPECIAL \
/* These two functions accept addr in network order */
const char * const * get_known_services(void);
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);
/**
* @brief Add two list of strings
*
* Create a new NULL-termintated list of strings by adding two lists together.
*
* @param[in] mem_ctx Talloc memory context for the new list.
* @param[in] l1 First NULL-termintated list of strings.
* @param[in] l2 Second NULL-termintated list of strings.
* @param[in] copy_strings If set to 'true' the list items will be copied
* otherwise only the pointers to the items are
* copied.
* @param[out] new_list New NULL-terminated list of strings. Must be freed
* with talloc_free() by the caller. If copy_strings
* is 'true' the new elements will be freed as well.
*/
bool copy_strings, char ***_new_list);
/**
* @brief set file descriptor as nonblocking
*
* Set the O_NONBLOCK flag for the input fd
*
* @param[in] fd The file descriptor to set as nonblocking
*
* @return EOK on success, errno code otherwise
*/
/* 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);
const char *input,
struct sss_domain_info *dom,
char **sanitized,
char **lc_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 size 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;
};
/* 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);
struct sss_domain_info *parent,
const char *name,
const char *realm,
const char *flat_name,
const char *id,
bool mpg,
bool enumerate,
const char *forest);
struct confdb_ctx *cdb,
const char *domain_name,
const char *db_path,
struct sss_domain_info **_domain);
/* the directory domain - realm mappings and other krb5 config snippers are
* written to */
struct sss_domain_info *start_dom,
char ***_dom_names,
int *_dom_names_count);
struct sss_domain_info *dom,
/* from util_lock.c */
#include "io.h"
#ifdef HAVE_PAC_RESPONDER
#define BUILD_WITH_PAC_RESPONDER true
#else
#define BUILD_WITH_PAC_RESPONDER false
#endif
/* 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);
#define GUID_BIN_LENGTH 16
/* 16 2-digit hex values + 4 dashes + terminating 0 */
/* from become_user.c */
struct sss_creds;
struct sss_creds **saved_creds);
/* from sss_semanage.c */
/* Please note that libsemange relies on files and directories created with
* certain permissions. Therefore the caller should make sure the umask is
* not too restricted (especially when called from the daemon code).
*/
const char *mlsrange);
int del_seuser(const char *login_name);
/* convert time from generalized form to unix time */
#endif /* __SSSD_UTIL_H__ */