util_errors.h revision 7650ded4ffa87fcf7ce5adf00920fecf89cffcf5
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,
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce ERR_INVALID_CRED_TYPE,
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce ERR_NO_CREDS,
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce ERR_CREDS_EXPIRED,
7c69221077c780e62f6c536e78675f2dc1c131bcMichal Zidek ERR_CREDS_EXPIRED_CCACHE,
22a21e910fd216ec1468fe769dcc29f1621a52a4Ondrej Kos ERR_CREDS_INVALID,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_NO_CACHED_CREDS,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_CACHED_CREDS_EXPIRED,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_AUTH_DENIED,
ab967283b710dfa05d11ee5b30c7ac916486ceecSimo Sorce ERR_AUTH_FAILED,
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ERR_CHPASS_DENIED,
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce ERR_CHPASS_FAILED,
c6872e79e8496fd075e20aec0343ade99cca725cSimo Sorce ERR_NETWORK_IO,
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ERR_ACCOUNT_EXPIRED,
233a3c6c48972b177e60d6ef4cecfacd3cf31659Simo Sorce ERR_PASSWORD_EXPIRED,
c9b0071bfcb8eb8c71e40248de46d23aceecc0f3Pavel Reichl ERR_PASSWORD_EXPIRED_REJECT,
c9b0071bfcb8eb8c71e40248de46d23aceecc0f3Pavel Reichl ERR_PASSWORD_EXPIRED_WARN,
c9b0071bfcb8eb8c71e40248de46d23aceecc0f3Pavel Reichl ERR_PASSWORD_EXPIRED_RENEW,
dfd71fc92db940b2892cc996911cec03d7b6c52bSimo Sorce ERR_ACCESS_DENIED,
f9961e5f82e0ef474d6492371bfdf9e74e208a99Pavel Březina ERR_SRV_NOT_FOUND,
f9961e5f82e0ef474d6492371bfdf9e74e208a99Pavel Březina ERR_SRV_LOOKUP_ERROR,
e5f455afbc2d149527bfd08f4e89903a3a8da17aPavel Březina ERR_SRV_DUPLICATES,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ERR_DYNDNS_FAILED,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ERR_DYNDNS_TIMEOUT,
9cb46bc62f22e0104f1b41a423b014c281ef5fc2Jakub Hrozek ERR_DYNDNS_OFFLINE,
7caf7ed4f2eae1ec1c0717b4ee6ce78bdacd5926Jakub Hrozek ERR_INPUT_PARSE,
dcc6877aa2e2dd63a9dc9c411a9c58feaeb36b9aStephen Gallagher ERR_NOT_FOUND,
bc30ce9b7d588a17e58012e699986f0d6898b791Pavel Březina ERR_DOMAIN_NOT_FOUND,
b5ee224324b0158641d9b110f81d2bc6eddddc13Pavel Reichl ERR_MISSING_CONF,
2a96981a0ac781d01e5bba473409ed2bdf4cd4e0Jakub Hrozek ERR_INVALID_FILTER,
e81deec535d11912b87954c81a1edd768c1386c9Jakub Hrozek ERR_NO_POSIX,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek ERR_DUP_EXTRA_ATTR,
4dd38025efda88f123eac672f87d3cda12f050c8Jakub Hrozek ERR_INVALID_EXTRA_ATTR,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ERR_SBUS_GET_SENDER_ERROR,
0161a3c5637a0c0092bf54c436bb3d6508d7df26Jakub Hrozek ERR_SBUS_NO_SENDER,
60cab26b12df9a2153823972cde0c38ca86e01b9Yassir Elley ERR_NO_SIDS,
1319e71fd1680ca4864afe0b1aca2b8c8e4a1ee4Stef Walter ERR_SBUS_NOSUP,
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek ERR_NO_SYSBUS,
a2ea3f5d9ef9f17efbb61e942c2bc6cff7d1ebf2Jakub Hrozek ERR_REFERRAL,
f3a25949de81f80c136bb073e4a8f504b080c20cJakub Hrozek ERR_SELINUX_CONTEXT,
8394eddba54b5d3e3fda868145e3751247bdbdb2Michal Zidek ERR_REGEX_NOMATCH,
5a5c5cdeb92f4012fc75fd717bfea06598f68f12Pavel Reichl ERR_TIMESPEC_NOT_SUPPORTED,
804df4040eb142f82a44c019c7a55b5ce524583cMichal Zidek ERR_INVALID_CONFIG,
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce ERR_LAST /* ALWAYS LAST */
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce};
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce
0c16d2eefbc6ac8331078a4cdcecfee817a71bc6Simo Sorce#define SSSD_ERR_BASE(err) ((err) & ~ERR_MASK)
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define SSSD_ERR_IDX(err) ((err) & ERR_MASK)
8bcabb97d988d1602882a1f036aac2eaf5e09234Simo Sorce#define IS_SSSD_ERROR(err) \
7650ded4ffa87fcf7ce5adf00920fecf89cffcf5Michal Zidek ((SSSD_ERR_BASE(err) == ERR_BASE) && ((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__ */