X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=ubusd_proto.c;h=72da7a73f22f4bf2176fa93a605b8a5bfa99f87d;hb=df088f03c02aebba304a371486f09e95ed34bf5f;hp=09faeb2ae3f7ed5c5a773186ae0a32fa9b077151;hpb=3df5b18af2c6b962ebd9ddea9208edadc3ea42e4;p=project%2Fubus.git diff --git a/ubusd_proto.c b/ubusd_proto.c index 09faeb2..72da7a7 100644 --- a/ubusd_proto.c +++ b/ubusd_proto.c @@ -80,11 +80,15 @@ void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub, uint8_t type) { + /* keep the fd to be passed if it is UBUS_MSG_INVOKE */ + int fd = ub->fd; ub = ubus_reply_from_blob(ub, true); if (!ub) return; ub->hdr.type = type; + ub->fd = fd; + ubus_msg_send(cl, ub, true); } @@ -130,8 +134,8 @@ static int ubusd_handle_remove_object(struct ubus_client *cl, struct ubus_msg_bu if (obj->type && obj->type->refcount == 1) blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id); - ubusd_free_object(obj); ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); + ubusd_free_object(obj); return 0; } @@ -146,7 +150,7 @@ static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf * blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id); - if (attr[UBUS_ATTR_SIGNATURE]) + if (attr[UBUS_ATTR_SIGNATURE] && obj->type) blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id); ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); @@ -156,9 +160,12 @@ static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf * static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, struct ubus_object *obj) { struct ubus_method *m; - int cnt = 0; + int all_cnt = 0, cnt = 0; void *s; + if (!obj->type) + return; + blob_buf_init(&b, 0); blob_put_string(&b, UBUS_ATTR_OBJPATH, obj->path.key); @@ -167,6 +174,7 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru s = blob_nest_start(&b, UBUS_ATTR_SIGNATURE); list_for_each_entry(m, &obj->type->methods, list) { + all_cnt++; if (!ubusd_acl_check(cl, obj->path.key, blobmsg_name(m->data), UBUS_ACL_ACCESS)) { blobmsg_add_blob(&b, m->data); cnt++; @@ -174,7 +182,7 @@ static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, stru } blob_nest_end(&b, s); - if (cnt) + if (cnt || !all_cnt) ubus_proto_send_msg_from_blob(cl, ub, UBUS_MSG_DATA); } @@ -257,7 +265,7 @@ static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub, method = blob_data(attr[UBUS_ATTR_METHOD]); if (ubusd_acl_check(cl, obj->path.key, method, UBUS_ACL_ACCESS)) - return UBUS_STATUS_NOT_FOUND; + return UBUS_STATUS_PERMISSION_DENIED; if (!obj->client) return obj->recv_msg(cl, ub, method, attr[UBUS_ATTR_DATA]); @@ -374,7 +382,7 @@ static int ubusd_handle_add_watch(struct ubus_client *cl, struct ubus_msg_buf *u return UBUS_STATUS_INVALID_ARGUMENT; target = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_TARGET])); - if (!target) + if (!target || !target->client) return UBUS_STATUS_NOT_FOUND; if (cl == target->client) @@ -443,7 +451,7 @@ void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub if (ub->hdr.type < __UBUS_MSG_LAST) cb = handlers[ub->hdr.type]; - if (ub->hdr.type != UBUS_MSG_STATUS) + if (ub->hdr.type != UBUS_MSG_STATUS && ub->hdr.type != UBUS_MSG_INVOKE) ubus_msg_close_fd(ub); if (cb) @@ -500,6 +508,7 @@ void ubusd_proto_free_client(struct ubus_client *cl) ubusd_free_object(obj); } + ubusd_acl_free_client(cl); ubus_free_id(&clients, &cl->id); }