util_errors.h revision ab967283b710dfa05d11ee5b30c7ac916486ceec
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/*
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce Copyright (C) 2012 Red Hat
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce This program is free software; you can redistribute it and/or modify
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce it under the terms of the GNU General Public License as published by
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce the Free Software Foundation; either version 3 of the License, or
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce (at your option) any later version.
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce This program is distributed in the hope that it will be useful,
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce but WITHOUT ANY WARRANTY; without even the implied warranty of
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce GNU General Public License for more details.
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce You should have received a copy of the GNU General Public License
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce along with this program. If not, see <http://www.gnu.org/licenses/>.
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce Authors:
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce Simo Sorce <ssorce@redhat.com>
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce*/
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#ifndef __SSSD_UTIL_ERRORS_H__
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define __SSSD_UTIL_ERRORS_H__
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#ifndef HAVE_ERRNO_T
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define HAVE_ERRNO_T
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorcetypedef int errno_t;
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#endif
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/*
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * We define a specific number space so that we do not overlap with other
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * generic errors returned by various libraries. This will make it easy
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * to have functions that double check that what was returned was a SSSD
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * specific error where it matters. For example we may want to ensure some
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * particularly sensitive paths only return SSSD sepcific errors as that
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * will insure all error conditions have been explicitly dealt with,
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * and are not the result of assigning the wrong return result.
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce *
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * Basic system errno errors can still be used, but when an error condition
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * does not properly map to a system error we should use a SSSD specific one
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define ERR_BASE 0x555D0000
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define ERR_MASK 0x0000FFFF
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/* never use ERR_INVALID, it is used for catching and returning
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * information on invalid error numbers */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/* never use ERR_LAST, this represent the maximum error value available
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * and is used to validate error codes */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorceenum sssd_errors {
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce ERR_INVALID = ERR_BASE + 0,
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce ERR_INTERNAL,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_ACCOUNT_UNKNOWN,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_NO_CACHED_CREDS,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_CACHED_CREDS_EXPIRED,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_AUTH_DENIED,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_AUTH_FAILED,
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce ERR_LAST /* ALWAYS LAST */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce};
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define SSSD_ERR_IDX(err) ((err) & ERR_MASK)
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define IS_SSSD_ERROR(err) \
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce ((((err) & ERR_BASE) == ERR_BASE) && \
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce SSSD_ERR_IDX(err) < ERR_LAST)
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define ERR_OK 0
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/* Backwards compat */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#ifndef EOK
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define EOK ERR_OK
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#endif
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce/**
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * @brief return a string descriing the error number like strerror()
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce *
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * @param error An errno_t number, can be a SSSD error or a system error
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce *
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce * @return A statically allocated string.
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorceconst char *sss_strerror(errno_t error);
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#endif /* __SSSD_UTIL_ERRORS_H__ */