util_errors.h revision 82a958e6592c4a4078e45b7197bbe4751b70f511
967e5f3c25249c779575864692935627004d3f9eChristian Maeder/*
967e5f3c25249c779575864692935627004d3f9eChristian Maeder Copyright (C) 2012 Red Hat
81d182b21020b815887e9057959228546cf61b6bChristian Maeder
f11f713bebd8e1e623a0a4361065df256033de47Christian Maeder This program is free software; you can redistribute it and/or modify
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu it under the terms of the GNU General Public License as published by
967e5f3c25249c779575864692935627004d3f9eChristian Maeder the Free Software Foundation; either version 3 of the License, or
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maeder (at your option) any later version.
967e5f3c25249c779575864692935627004d3f9eChristian Maeder
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian Maeder This program is distributed in the hope that it will be useful,
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder GNU General Public License for more details.
967e5f3c25249c779575864692935627004d3f9eChristian Maeder
967e5f3c25249c779575864692935627004d3f9eChristian Maeder You should have received a copy of the GNU General Public License
967e5f3c25249c779575864692935627004d3f9eChristian Maeder along with this program. If not, see <http://www.gnu.org/licenses/>.
967e5f3c25249c779575864692935627004d3f9eChristian Maeder
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder Authors:
7221c71b38c871ce66eee4537cb681d468308dfbChristian Maeder Simo Sorce <ssorce@redhat.com>
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder*/
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder#ifndef __SSSD_UTIL_ERRORS_H__
ac19f8695aa1b2d2d1cd1319da2530edd8f46a96Christian Maeder#define __SSSD_UTIL_ERRORS_H__
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maeder
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder#ifndef HAVE_ERRNO_T
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder#define HAVE_ERRNO_T
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian Maedertypedef int errno_t;
4ef2a978e66e2246ff0b7f00c77deb7aabb28b8eChristian Maeder#endif
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder/*
967e5f3c25249c779575864692935627004d3f9eChristian Maeder * We define a specific number space so that we do not overlap with other
8e9c3881fb6e710b1e08bf5ac8ff9d393df2e74eChristian Maeder * generic errors returned by various libraries. This will make it easy
78eeae099616e255ccf2e5f9122387bb10c68338Christian Maeder * to have functions that double check that what was returned was a SSSD
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder * specific error where it matters. For example we may want to ensure some
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder * particularly sensitive paths only return SSSD sepcific errors as that
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder * will insure all error conditions have been explicitly dealt with,
ad187062b0009820118c1b773a232e29b879a2faChristian Maeder * and are not the result of assigning the wrong return result.
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder *
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder * Basic system errno errors can still be used, but when an error condition
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder * does not properly map to a system error we should use a SSSD specific one
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder */
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder#define ERR_BASE 0x555D0000
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder#define ERR_MASK 0x0000FFFF
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder/* never use ERR_INVALID, it is used for catching and returning
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder * information on invalid error numbers */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder/* never use ERR_LAST, this represent the maximum error value available
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maeder * and is used to validate error codes */
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederenum sssd_errors {
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_INVALID = ERR_BASE + 0,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_INTERNAL,
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maeder ERR_ACCOUNT_UNKNOWN,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_INVALID_CRED_TYPE,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_NO_CREDS,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_CREDS_EXPIRED,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_CREDS_EXPIRED_CCACHE,
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder ERR_CREDS_INVALID,
72b9099aeec0762bae4546db3bc4b48721027bf4Christian Maeder ERR_NO_CACHED_CREDS,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_CACHED_CREDS_EXPIRED,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_AUTH_DENIED,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_AUTH_FAILED,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_CHPASS_DENIED,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_CHPASS_FAILED,
7a879b08ae0ca30006f9be887a73212b07f10204Christian Maeder ERR_NETWORK_IO,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_ACCOUNT_EXPIRED,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_PASSWORD_EXPIRED,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_PASSWORD_EXPIRED_REJECT,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_PASSWORD_EXPIRED_WARN,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_PASSWORD_EXPIRED_RENEW,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_ACCESS_DENIED,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_SRV_NOT_FOUND,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_SRV_LOOKUP_ERROR,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_SRV_DUPLICATES,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_DYNDNS_FAILED,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_DYNDNS_TIMEOUT,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_DYNDNS_OFFLINE,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_INPUT_PARSE,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_NOT_FOUND,
7a879b08ae0ca30006f9be887a73212b07f10204Christian Maeder ERR_DOMAIN_NOT_FOUND,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_MISSING_CONF,
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ERR_INVALID_FILTER,
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maeder ERR_NO_POSIX,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_DUP_EXTRA_ATTR,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_INVALID_EXTRA_ATTR,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_SBUS_GET_SENDER_ERROR,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_SBUS_NO_SENDER,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_NO_SIDS,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_SBUS_NOSUP,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_NO_SYSBUS,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_REFERRAL,
a89389521ddf76109168a0b339031575aafbd512Christian Maeder ERR_SELINUX_CONTEXT,
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder ERR_REGEX_NOMATCH,
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder ERR_TIMESPEC_NOT_SUPPORTED,
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder ERR_INVALID_CONFIG,
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder ERR_MALFORMED_ENTRY,
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder ERR_UNEXPECTED_ENTRY_TYPE,
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder ERR_SIMPLE_GROUPS_MISSING,
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder ERR_LAST /* ALWAYS LAST */
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder};
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder#define SSSD_ERR_BASE(err) ((err) & ~ERR_MASK)
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder#define SSSD_ERR_IDX(err) ((err) & ERR_MASK)
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder#define IS_SSSD_ERROR(err) \
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder ((SSSD_ERR_BASE(err) == ERR_BASE) && ((err) <= ERR_LAST))
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder#define ERR_OK 0
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder/* Backwards compat */
e77eadd37125110f448dd5ddec7da5b78d35285fChristian Maeder#ifndef EOK
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder#define EOK ERR_OK
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder#endif
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder/**
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder * @brief return a string descriing the error number like strerror()
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder *
ceef5f7843a1f96fe5a62e0f6880e38b3d5f4708Christian Maeder * @param error An errno_t number, can be a SSSD error or a system error
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder *
54ff63bb3b23ef18efbdc51b053a2ca6f348329aChristian Maeder * @return A statically allocated string.
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder */
67086e0fe40a985c5e8a3cf50e611f43234580c2Christian Maederconst char *sss_strerror(errno_t error);
e77eadd37125110f448dd5ddec7da5b78d35285fChristian Maeder
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder#endif /* __SSSD_UTIL_ERRORS_H__ */
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder