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