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