sssd  2.2.3
About: SSSD provides a set of daemons to manage access to remote directories and authentication mechanisms such as LDAP, Kerberos or FreeIPA. It provides also an NSS and PAM interface toward the system.
  Fossies Dox: sssd-2.2.3.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sbus_errors.c
Go to the documentation of this file.
1 /*
2  Authors:
3  Pavel Březina <pbrezina@redhat.com>
4 
5  Copyright (C) 2017 Red Hat
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <errno.h>
22 #include <dbus/dbus.h>
23 
24 #include "util/util.h"
25 #include "util/util_errors.h"
26 #include "util/strtonum.h"
27 #include "sbus/sbus_errors.h"
28 
29 static const struct {
30  const char *name;
32 } sbus_error_table[] = {
33  /* Custom errors. */
35  { SBUS_ERROR_NOT_FOUND, ENOENT },
37 
38  /* D-Bus standard errors. Some errno values may overlap, but when
39  * finding its D-Bus pair the first match is returned. */
40  { DBUS_ERROR_SERVICE_UNKNOWN, ERR_SBUS_UNKNOWN_SERVICE},
41  { DBUS_ERROR_UNKNOWN_INTERFACE, ERR_SBUS_UNKNOWN_INTERFACE},
42  { DBUS_ERROR_UNKNOWN_PROPERTY, ERR_SBUS_UNKNOWN_PROPERTY},
43  { DBUS_ERROR_NAME_HAS_NO_OWNER, ERR_SBUS_UNKNOWN_OWNER},
44  { DBUS_ERROR_NO_REPLY, ERR_SBUS_NO_REPLY},
45  { DBUS_ERROR_FAILED, EFAULT},
46  { DBUS_ERROR_NO_MEMORY, ENOMEM},
47  { DBUS_ERROR_TIMEOUT, ETIMEDOUT},
48  { DBUS_ERROR_NO_REPLY, ETIMEDOUT},
49  { DBUS_ERROR_IO_ERROR, EIO},
50  { DBUS_ERROR_BAD_ADDRESS, EFAULT},
51  { DBUS_ERROR_NOT_SUPPORTED, ENOTSUP},
52  { DBUS_ERROR_LIMITS_EXCEEDED, ERANGE},
53  { DBUS_ERROR_ACCESS_DENIED, EPERM},
54  { DBUS_ERROR_AUTH_FAILED, EACCES},
55  { DBUS_ERROR_NO_NETWORK, ENONET},
56  { DBUS_ERROR_DISCONNECTED, ERR_OFFLINE},
57  { DBUS_ERROR_INVALID_ARGS, EINVAL},
58 
59  /* Should not happen so it can be as last item. */
61  { NULL, -1 }
62 };
63 
65 {
66  uint32_t ret;
67  int i;
68 
69  if (!dbus_error_is_set(error)) {
70  return EOK;
71  }
72 
73  if (dbus_error_has_name(error, SBUS_ERROR_ERRNO)) {
74  ret = strtouint32(error->message, NULL, 10);
75  if (errno != 0) {
76  DEBUG(SSSDBG_CRIT_FAILURE, "Unexpected error format: [%s]\n",
77  error->message);
78  return ERR_INTERNAL;
79  } else if (ret == EOK) {
80  DEBUG(SSSDBG_CRIT_FAILURE, "An error was send but it indicates "
81  "success: [%s]\n", error->message);
82  return ERR_INTERNAL;
83  }
84 
85  return ret;
86  }
87 
88  for (i = 0; sbus_error_table[i].name != NULL; i++) {
89  if (dbus_error_has_name(error, sbus_error_table[i].name)) {
90  return sbus_error_table[i].ret;
91  }
92  }
93 
94  return EIO;
95 }
96 
97 void
98 sbus_errno_to_error(TALLOC_CTX *mem_ctx,
99  errno_t ret,
100  const char **_error_name,
101  const char **_error_message)
102 {
103  char *message;
104  int i;
105 
106  for (i = 0; sbus_error_table[i].ret != -1; i++) {
107  if (sbus_error_table[i].ret == ret) {
108  *_error_name = sbus_error_table[i].name;
109  *_error_message = sss_strerror(ret);
110  return;
111  }
112  }
113 
114  /* Error code was not translated. Create generic errno message. */
115  message = talloc_asprintf(mem_ctx, "%u: %s", ret, sss_strerror(ret));
116  if (message == NULL) {
117  *_error_name = DBUS_ERROR_NO_MEMORY;
118  *_error_message = sss_strerror(ENOMEM);
119  return;
120  }
121 
122  *_error_name = SBUS_ERROR_ERRNO;
123  *_error_message = message;
124 
125  return;
126 }
ERR_SBUS_UNKNOWN_OWNER
@ ERR_SBUS_UNKNOWN_OWNER
Definition: util_errors.h:158
sss_strerror
const char * sss_strerror(errno_t error)
return a string describing the error number like strerror()
Definition: util_errors.c:150
EOK
#define EOK
Definition: hbac_evaluator.c:40
SBUS_ERROR_SUCCESS
#define SBUS_ERROR_SUCCESS
Definition: sbus_errors.h:29
SBUS_ERROR_NOT_FOUND
#define SBUS_ERROR_NOT_FOUND
Definition: sbus_errors.h:32
sbus_error_to_errno
errno_t sbus_error_to_errno(DBusError *error)
Definition: sbus_errors.c:64
strtouint32
uint32_t strtouint32(const char *nptr, char **endptr, int base)
Definition: strtonum.c:52
ERR_INTERNAL
@ ERR_INTERNAL
Definition: util_errors.h:51
sbus_errno_to_error
void sbus_errno_to_error(TALLOC_CTX *mem_ctx, errno_t ret, const char **_error_name, const char **_error_message)
Definition: sbus_errors.c:98
DEBUG
#define DEBUG(level, format,...)
macro to generate debug messages
Definition: debug.h:123
ERR_SBUS_UNKNOWN_INTERFACE
@ ERR_SBUS_UNKNOWN_INTERFACE
Definition: util_errors.h:156
SBUS_ERROR_INTERNAL
#define SBUS_ERROR_INTERNAL
Definition: sbus_errors.h:31
strtonum.h
SBUS_ERROR_KILLED
#define SBUS_ERROR_KILLED
Definition: sbus_errors.h:33
errno_t
int errno_t
Definition: hbac_evaluator.c:36
sbus_error_table
static const struct @81 sbus_error_table[]
util_errors.h
ERR_SBUS_UNKNOWN_PROPERTY
@ ERR_SBUS_UNKNOWN_PROPERTY
Definition: util_errors.h:157
name
const char * name
Definition: sbus_errors.c:30
SSSDConfigTest.error
int error
Definition: SSSDConfigTest.py:2129
sbus_errors.h
ERR_SBUS_UNKNOWN_SERVICE
@ ERR_SBUS_UNKNOWN_SERVICE
Definition: util_errors.h:155
ERR_SBUS_KILL_CONNECTION
@ ERR_SBUS_KILL_CONNECTION
Definition: util_errors.h:150
SSSDBG_CRIT_FAILURE
#define SSSDBG_CRIT_FAILURE
Definition: debug.h:75
ERR_SBUS_NO_REPLY
@ ERR_SBUS_NO_REPLY
Definition: util_errors.h:159
NULL
#define NULL
Definition: util.h:67
ERR_OFFLINE
@ ERR_OFFLINE
Definition: util_errors.h:54
util.h
ret
errno_t ret
Definition: sbus_errors.c:31
SBUS_ERROR_ERRNO
#define SBUS_ERROR_ERRNO
Definition: sbus_errors.h:34