Ubus
OpenWrt system message/RPC bus.
libubus-acl.c File Reference
#include <unistd.h>
#include <libubox/blob.h>
#include <libubox/blobmsg.h>
#include "libubus.h"
#include <libubox/avl-cmp.h>

Go to the source code of this file.

Enumerations

enum  {
  ACL_OBJ_OBJECT , ACL_OBJ_USER , ACL_OBJ_GROUP , ACL_OBJ_ACL ,
  __ACL_OBJ_MAX
}
 
enum  { ACL_POLICY_SEQ , ACL_POLICY_ACL , __ACL_POLICY_MAX }
 

Functions

static int acl_cmp (const void *k1, const void *k2, void *ptr)
 
 AVL_TREE (acl_objects, acl_cmp, true, NULL)
 
static void acl_add (struct blob_attr *obj)
 
static void acl_recv_cb (struct ubus_request *req, int type, struct blob_attr *msg)
 
static void acl_query (struct ubus_context *ctx)
 
static void acl_subscribe_cb (struct ubus_context *ctx, struct ubus_event_handler *ev, const char *type, struct blob_attr *msg)
 
int ubus_register_acl (struct ubus_context *ctx)
 

Variables

static struct ubus_event_handler acl_event
 
static struct ubus_request acl_req
 
static struct blob_attr * acl_blob
 
static const struct blobmsg_policy acl_obj_policy [__ACL_OBJ_MAX]
 
static const struct blobmsg_policy acl_policy [__ACL_POLICY_MAX]
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ACL_OBJ_OBJECT 
ACL_OBJ_USER 
ACL_OBJ_GROUP 
ACL_OBJ_ACL 
__ACL_OBJ_MAX 

Definition at line 47 of file libubus-acl.c.

47  {
53 };
@ __ACL_OBJ_MAX
Definition: libubus-acl.c:52
@ ACL_OBJ_ACL
Definition: libubus-acl.c:51
@ ACL_OBJ_USER
Definition: libubus-acl.c:49
@ ACL_OBJ_GROUP
Definition: libubus-acl.c:50
@ ACL_OBJ_OBJECT
Definition: libubus-acl.c:48

◆ anonymous enum

anonymous enum
Enumerator
ACL_POLICY_SEQ 
ACL_POLICY_ACL 
__ACL_POLICY_MAX 

Definition at line 89 of file libubus-acl.c.

89  {
93 };
@ __ACL_POLICY_MAX
Definition: libubus-acl.c:92
@ ACL_POLICY_ACL
Definition: libubus-acl.c:91
@ ACL_POLICY_SEQ
Definition: libubus-acl.c:90

Function Documentation

◆ acl_add()

static void acl_add ( struct blob_attr *  obj)
static

Definition at line 63 of file libubus-acl.c.

64 {
65  struct blob_attr *tb[__ACL_OBJ_MAX];
66  struct acl_object *acl;
67 
68  blobmsg_parse(acl_obj_policy, __ACL_OBJ_MAX, tb, blobmsg_data(obj),
69  blobmsg_data_len(obj));
70 
71  if (!tb[ACL_OBJ_OBJECT] || !tb[ACL_OBJ_ACL])
72  return;
73 
74  if (!tb[ACL_OBJ_USER] && !tb[ACL_OBJ_GROUP])
75  return;
76 
77  acl = calloc(1, sizeof(*acl));
78  if (!acl)
79  return;
80 
81  acl->avl.key = &acl->key;
82  acl->key.object = blobmsg_get_string(tb[ACL_OBJ_OBJECT]);
83  acl->key.user = blobmsg_get_string(tb[ACL_OBJ_USER]);
84  acl->key.group = blobmsg_get_string(tb[ACL_OBJ_GROUP]);
85  acl->acl = tb[ACL_OBJ_ACL];
86  avl_insert(&acl_objects, &acl->avl);
87 }
static const struct blobmsg_policy acl_obj_policy[__ACL_OBJ_MAX]
Definition: libubus-acl.c:55
struct avl_tree acl_objects
struct blob_attr * acl
Definition: libubus.h:337
Here is the caller graph for this function:

◆ acl_cmp()

static int acl_cmp ( const void *  k1,
const void *  k2,
void *  ptr 
)
static

Definition at line 26 of file libubus-acl.c.

27 {
28  const struct ubus_acl_key *key1 = k1;
29  const struct ubus_acl_key *key2 = k2;
30  int ret = 0;
31 
32  if (key1->user && key2->user)
33  ret = strcmp(key1->user, key2->user);
34  if (ret)
35  return ret;
36 
37  if (key1->group && key2->group)
38  ret = strcmp(key1->group, key2->group);
39  if (ret)
40  return ret;
41 
42  return strcmp(key1->object, key2->object);
43 }
const char * group
Definition: libubus.h:190
const char * object
Definition: libubus.h:191
const char * user
Definition: libubus.h:189

◆ acl_query()

static void acl_query ( struct ubus_context ctx)
static

Definition at line 127 of file libubus-acl.c.

128 {
132 }
static struct ubus_context * ctx
Definition: client.c:22
static void acl_recv_cb(struct ubus_request *req, int type, struct blob_attr *msg)
Definition: libubus-acl.c:100
static struct ubus_request acl_req
Definition: libubus-acl.c:23
void ubus_complete_request_async(struct ubus_context *ctx, struct ubus_request *req)
Definition: libubus-req.c:90
static int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, struct blob_attr *msg, struct ubus_request *req)
Definition: libubus.h:365
ubus_data_handler_t data_cb
Definition: libubus.h:221
#define UBUS_SYSTEM_OBJECT_ACL
Definition: ubusmsg.h:25
Here is the call graph for this function:
Here is the caller graph for this function:

◆ acl_recv_cb()

static void acl_recv_cb ( struct ubus_request req,
int  type,
struct blob_attr *  msg 
)
static

Definition at line 100 of file libubus-acl.c.

102 {
103  struct blob_attr *tb[__ACL_POLICY_MAX];
104  struct blob_attr *cur;
105  size_t rem;
106 
107  if (acl_blob) {
108  struct acl_object *p, *q;
109 
110  avl_for_each_element_safe(&acl_objects, p, avl, q) {
111  avl_delete(&acl_objects, &p->avl);
112  free(p);
113  }
114  free(acl_blob);
115  }
116  acl_blob = blob_memdup(msg);
117  blobmsg_parse(acl_policy, __ACL_POLICY_MAX, tb, blobmsg_data(msg),
118  blobmsg_data_len(msg));
119 
120  if (!tb[ACL_POLICY_SEQ] && !tb[ACL_POLICY_ACL])
121  return;
122 
123  blobmsg_for_each_attr(cur, tb[ACL_POLICY_ACL], rem)
124  acl_add(cur);
125 }
static void acl_add(struct blob_attr *obj)
Definition: libubus-acl.c:63
static const struct blobmsg_policy acl_policy[__ACL_POLICY_MAX]
Definition: libubus-acl.c:95
static struct blob_attr * acl_blob
Definition: libubus-acl.c:24
struct avl_node avl
Definition: libubus.h:336
Here is the call graph for this function:
Here is the caller graph for this function:

◆ acl_subscribe_cb()

static void acl_subscribe_cb ( struct ubus_context ctx,
struct ubus_event_handler ev,
const char *  type,
struct blob_attr *  msg 
)
static

Definition at line 134 of file libubus-acl.c.

136 {
137  if (strcmp(type, "ubus.acl.sequence"))
138  return;
139  acl_query(ctx);
140 }
static void acl_query(struct ubus_context *ctx)
Definition: libubus-acl.c:127
uint8_t type
Definition: ubusmsg.h:1
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AVL_TREE()

AVL_TREE ( acl_objects  ,
acl_cmp  ,
true  ,
NULL   
)

◆ ubus_register_acl()

int ubus_register_acl ( struct ubus_context ctx)

Definition at line 142 of file libubus-acl.c.

143 {
144  int ret;
145 
147 
148  ret = ubus_register_event_handler(ctx, &acl_event, "ubus.acl.sequence");
149  if (!ret)
150  acl_query(ctx);
151 
152  return ret;
153 }
static struct ubus_event_handler acl_event
Definition: libubus-acl.c:22
static void acl_subscribe_cb(struct ubus_context *ctx, struct ubus_event_handler *ev, const char *type, struct blob_attr *msg)
Definition: libubus-acl.c:134
int ubus_register_event_handler(struct ubus_context *ctx, struct ubus_event_handler *ev, const char *pattern)
Definition: libubus.c:225
ubus_event_handler_t cb
Definition: libubus.h:154
Here is the call graph for this function:

Variable Documentation

◆ acl_blob

struct blob_attr* acl_blob
static

Definition at line 24 of file libubus-acl.c.

◆ acl_event

struct ubus_event_handler acl_event
static

Definition at line 1 of file libubus-acl.c.

◆ acl_obj_policy

const struct blobmsg_policy acl_obj_policy[__ACL_OBJ_MAX]
static
Initial value:
= {
[ACL_OBJ_OBJECT] = { .name = "obj", .type = BLOBMSG_TYPE_STRING },
[ACL_OBJ_USER] = { .name = "user", .type = BLOBMSG_TYPE_STRING },
[ACL_OBJ_GROUP] = { .name = "group", .type = BLOBMSG_TYPE_STRING },
[ACL_OBJ_ACL] = { .name = "acl", .type = BLOBMSG_TYPE_TABLE },
}

Definition at line 45 of file libubus-acl.c.

◆ acl_policy

const struct blobmsg_policy acl_policy[__ACL_POLICY_MAX]
static
Initial value:
= {
[ACL_POLICY_SEQ] = { .name = "seq", .type = BLOBMSG_TYPE_INT32 },
[ACL_POLICY_ACL] = { .name = "acl", .type = BLOBMSG_TYPE_ARRAY },
}

Definition at line 63 of file libubus-acl.c.

◆ acl_req

struct ubus_request acl_req
static

Definition at line 1 of file libubus-acl.c.