projects
/
project
/
ubus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
CMakeLists.txt: bump minimum cmake version
[project/ubus.git]
/
libubus-obj.c
diff --git
a/libubus-obj.c
b/libubus-obj.c
index bdb2e03478d70541691448ff7e2b672e0711871e..29cbb2b98e6eab48d8cd280e6ca2a596da1ff729 100644
(file)
--- a/
libubus-obj.c
+++ b/
libubus-obj.c
@@
-11,12
+11,13
@@
* GNU General Public License for more details.
*/
* GNU General Public License for more details.
*/
+#include <unistd.h>
#include "libubus.h"
#include "libubus-internal.h"
static void
ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr,
#include "libubus.h"
#include "libubus-internal.h"
static void
ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr,
- struct ubus_object *obj, struct blob_attr **attrbuf)
+ struct ubus_object *obj, struct blob_attr **attrbuf
, int fd
)
{
struct ubus_subscriber *s;
{
struct ubus_subscriber *s;
@@
-29,11
+30,14
@@
ubus_process_unsubscribe(struct ubus_context *ctx, struct ubus_msghdr *hdr,
s = container_of(obj, struct ubus_subscriber, obj);
if (s->remove_cb)
s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET]));
s = container_of(obj, struct ubus_subscriber, obj);
if (s->remove_cb)
s->remove_cb(ctx, s, blob_get_u32(attrbuf[UBUS_ATTR_TARGET]));
+
+ if (fd >= 0)
+ close(fd);
}
static void
ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr,
}
static void
ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr,
- struct ubus_object *obj, struct blob_attr **attrbuf)
+ struct ubus_object *obj, struct blob_attr **attrbuf
, int fd
)
{
if (!obj || !attrbuf[UBUS_ATTR_ACTIVE])
return;
{
if (!obj || !attrbuf[UBUS_ATTR_ACTIVE])
return;
@@
-41,12
+45,19
@@
ubus_process_notify(struct ubus_context *ctx, struct ubus_msghdr *hdr,
obj->has_subscribers = blob_get_u8(attrbuf[UBUS_ATTR_ACTIVE]);
if (obj->subscribe_cb)
obj->subscribe_cb(ctx, obj);
obj->has_subscribers = blob_get_u8(attrbuf[UBUS_ATTR_ACTIVE]);
if (obj->subscribe_cb)
obj->subscribe_cb(ctx, obj);
+
+ if (fd >= 0)
+ close(fd);
}
static void
ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr,
}
static void
ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr,
- struct ubus_object *obj, struct blob_attr **attrbuf)
+ struct ubus_object *obj, struct blob_attr **attrbuf
, int fd
)
{
{
- struct ubus_request_data req = {};
+ struct ubus_request_data req = {
+ .fd = -1,
+ .req_fd = fd,
+ };
+
int method;
int ret;
bool no_reply = false;
int method;
int ret;
bool no_reply = false;
@@
-67,7
+78,11
@@
ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr,
req.peer = hdr->peer;
req.seq = hdr->seq;
req.object = obj->id;
req.peer = hdr->peer;
req.seq = hdr->seq;
req.object = obj->id;
-
+ if (attrbuf[UBUS_ATTR_USER] && attrbuf[UBUS_ATTR_GROUP]) {
+ req.acl.user = blobmsg_get_string(attrbuf[UBUS_ATTR_USER]);
+ req.acl.group = blobmsg_get_string(attrbuf[UBUS_ATTR_GROUP]);
+ req.acl.object = obj->name;
+ }
for (method = 0; method < obj->n_methods; method++)
if (!obj->methods[method].name ||
!strcmp(obj->methods[method].name,
for (method = 0; method < obj->n_methods; method++)
if (!obj->methods[method].name ||
!strcmp(obj->methods[method].name,
@@
-79,9
+94,16
@@
ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr,
goto send;
found:
goto send;
found:
+ if (!attrbuf[UBUS_ATTR_DATA]) {
+ ret = UBUS_STATUS_INVALID_ARGUMENT;
+ goto send;
+ }
+
ret = obj->methods[method].handler(ctx, obj, &req,
blob_data(attrbuf[UBUS_ATTR_METHOD]),
attrbuf[UBUS_ATTR_DATA]);
ret = obj->methods[method].handler(ctx, obj, &req,
blob_data(attrbuf[UBUS_ATTR_METHOD]),
attrbuf[UBUS_ATTR_DATA]);
+ if (req.req_fd >= 0)
+ close(req.req_fd);
if (req.deferred || no_reply)
return;
if (req.deferred || no_reply)
return;
@@
-89,15
+111,17
@@
send:
ubus_complete_deferred_request(ctx, &req, ret);
}
ubus_complete_deferred_request(ctx, &req, ret);
}
-void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr)
+
+void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
{
void (*cb)(struct ubus_context *, struct ubus_msghdr *,
{
void (*cb)(struct ubus_context *, struct ubus_msghdr *,
- struct ubus_object *, struct blob_attr **);
+ struct ubus_object *, struct blob_attr **, int fd);
+ struct ubus_msghdr *hdr = &buf->hdr;
struct blob_attr **attrbuf;
struct ubus_object *obj;
uint32_t objid;
struct blob_attr **attrbuf;
struct ubus_object *obj;
uint32_t objid;
-
- attrbuf = ubus_parse_msg(
hdr->data
);
+ void *prev_data = NULL;
+ attrbuf = ubus_parse_msg(
buf->data, blob_raw_len(buf->data)
);
if (!attrbuf[UBUS_ATTR_OBJID])
return;
if (!attrbuf[UBUS_ATTR_OBJID])
return;
@@
-117,13
+141,26
@@
void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr
default:
return;
}
default:
return;
}
- cb(ctx, hdr, obj, attrbuf);
+
+ if (buf == &ctx->msgbuf) {
+ prev_data = buf->data;
+ buf->data = NULL;
+ }
+
+ cb(ctx, hdr, obj, attrbuf, fd);
+
+ if (prev_data) {
+ if (buf->data)
+ free(prev_data);
+ else
+ buf->data = prev_data;
+ }
}
static void ubus_add_object_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct ubus_object *obj = req->priv;
}
static void ubus_add_object_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct ubus_object *obj = req->priv;
- struct blob_attr **attrbuf = ubus_parse_msg(msg);
+ struct blob_attr **attrbuf = ubus_parse_msg(msg
, blob_raw_len(msg)
);
if (!attrbuf[UBUS_ATTR_OBJID])
return;
if (!attrbuf[UBUS_ATTR_OBJID])
return;
@@
-144,8
+181,12
@@
static void ubus_push_method_data(const struct ubus_method *m)
mtbl = blobmsg_open_table(&b, m->name);
mtbl = blobmsg_open_table(&b, m->name);
- for (i = 0; i < m->n_policy; i++)
+ for (i = 0; i < m->n_policy; i++) {
+ if (m->mask && !(m->mask & (1 << i)))
+ continue;
+
blobmsg_add_u32(&b, m->policy[i].name, m->policy[i].type);
blobmsg_add_u32(&b, m->policy[i].name, m->policy[i].type);
+ }
blobmsg_close_table(&b, mtbl);
}
blobmsg_close_table(&b, mtbl);
}
@@
-199,17
+240,17
@@
int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj)
static void ubus_remove_object_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct ubus_object *obj = req->priv;
static void ubus_remove_object_cb(struct ubus_request *req, int type, struct blob_attr *msg)
{
struct ubus_object *obj = req->priv;
- struct blob_attr **attrbuf = ubus_parse_msg(msg);
+ struct blob_attr **attrbuf = ubus_parse_msg(msg
, blob_raw_len(msg)
);
if (!attrbuf[UBUS_ATTR_OBJID])
return;
if (!attrbuf[UBUS_ATTR_OBJID])
return;
+ avl_delete(&req->ctx->objects, &obj->avl);
+
obj->id = 0;
if (attrbuf[UBUS_ATTR_OBJTYPE] && obj->type)
obj->type->id = 0;
obj->id = 0;
if (attrbuf[UBUS_ATTR_OBJTYPE] && obj->type)
obj->type->id = 0;
-
- avl_delete(&req->ctx->objects, &obj->avl);
}
int ubus_remove_object(struct ubus_context *ctx, struct ubus_object *obj)
}
int ubus_remove_object(struct ubus_context *ctx, struct ubus_object *obj)