-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathacl.c
More file actions
107 lines (86 loc) · 2.63 KB
/
acl.c
File metadata and controls
107 lines (86 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (C) 2016 prpl Foundation
* Written by Felix Fietkau <nbd@nbd.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "scapi.h"
#include "scald.h"
static struct ubus_request_data *ubus_req;
static const char *ubus_method;
static struct ubus_method acl_object_methods[] = {};
static struct ubus_object_type acl_object_type =
UBUS_OBJECT_TYPE("scald.acl", acl_object_methods);
static struct ubus_object acl_object = {
.type = &acl_object_type,
.methods = acl_object_methods,
.n_methods = ARRAY_SIZE(acl_object_methods),
};
void
scald_acl_req_init(struct ubus_request_data *req, const char *method)
{
ubus_req = req;
ubus_method = method;
}
void
scald_acl_req_done(void)
{
ubus_req = NULL;
ubus_method = NULL;
}
struct ubus_event_req {
struct ubus_notify_request req;
bool deny;
};
static void
acl_event_cb(struct ubus_notify_request *req, int idx, int ret)
{
struct ubus_event_req *ureq = container_of(req, struct ubus_event_req, req);
if (ret)
ureq->deny = true;
}
int
scald_acl_req_check(struct scapi_ptr *ptr, enum scapi_ptr_type type)
{
struct ubus_event_req ureq = {};
struct blob_buf *buf;
void *c;
buf = scald_event_new(&acl_object);
if (!buf)
return 0;
blobmsg_add_string(buf, "method", ubus_method);
c = blobmsg_open_table(buf, "ubus");
if (ubus_req->acl.user)
blobmsg_add_string(buf, "user", ubus_req->acl.user);
if (ubus_req->acl.group)
blobmsg_add_string(buf, "group", ubus_req->acl.group);
blobmsg_close_array(buf, c);
scald_event_add_ptr(buf, ptr, type);
if (ubus_notify_async(ubus_ctx, &acl_object, "check", buf->head, &ureq.req))
return 0;
ureq.req.status_cb = acl_event_cb;
ubus_complete_request(ubus_ctx, &ureq.req.req, 1000);
if (ureq.deny)
return SC_ERR_ACCESS_DENIED;
return 0;
}
void scald_acl_init(struct ubus_context *ctx)
{
char *name;
name = malloc(strlen(ubus_prefix) + 5);
if (!name)
return;
sprintf(name, "%s.acl", ubus_prefix);
acl_object.name = name;
ubus_add_object(ctx, &acl_object);
}