Line data Source code
1 : /*
2 : SSSD
3 :
4 : Data Provider Helpers
5 :
6 : Copyright (C) Stephen Gallagher <sgallagh@redhat.com> 2009
7 :
8 : This program is free software; you can redistribute it and/or modify
9 : it under the terms of the GNU General Public License as published by
10 : the Free Software Foundation; either version 3 of the License, or
11 : (at your option) any later version.
12 :
13 : This program is distributed in the hope that it will be useful,
14 : but WITHOUT ANY WARRANTY; without even the implied warranty of
15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 : GNU General Public License for more details.
17 :
18 : You should have received a copy of the GNU General Public License
19 : along with this program. If not, see <http://www.gnu.org/licenses/>.
20 : */
21 :
22 : #include <talloc.h>
23 :
24 : #include "util/util.h"
25 : #include "sbus_client.h"
26 :
27 0 : int sbus_client_init(TALLOC_CTX *mem_ctx,
28 : struct tevent_context *ev,
29 : const char *server_address,
30 : struct sbus_connection **_conn)
31 : {
32 0 : struct sbus_connection *conn = NULL;
33 : int ret;
34 : char *filename;
35 : uid_t check_uid;
36 : gid_t check_gid;
37 :
38 : /* Validate input */
39 0 : if (server_address == NULL) {
40 0 : return EINVAL;
41 : }
42 :
43 0 : filename = strchr(server_address, '/');
44 0 : if (filename == NULL) {
45 0 : DEBUG(SSSDBG_CRIT_FAILURE,
46 : "Unexpected dbus address [%s].\n", server_address);
47 0 : return EIO;
48 : }
49 :
50 0 : check_uid = geteuid();
51 0 : check_gid = getegid();
52 :
53 : /* Ignore ownership checks when the server runs as root. This is the
54 : * case when privileged monitor is setting up sockets for unprivileged
55 : * responders */
56 0 : if (check_uid == 0) check_uid = -1;
57 0 : if (check_gid == 0) check_gid = -1;
58 :
59 0 : ret = check_file(filename, check_uid, check_gid,
60 : S_IFSOCK|S_IRUSR|S_IWUSR, 0, NULL, true);
61 0 : if (ret != EOK) {
62 0 : DEBUG(SSSDBG_CRIT_FAILURE, "check_file failed for [%s].\n", filename);
63 0 : return EIO;
64 : }
65 :
66 0 : ret = sbus_new_connection(mem_ctx, ev, server_address, &conn);
67 0 : if (ret != EOK) {
68 0 : goto fail;
69 : }
70 :
71 0 : *_conn = conn;
72 0 : return EOK;
73 :
74 : fail:
75 0 : talloc_free(conn);
76 0 : return ret;
77 : }
|