summaryrefslogtreecommitdiff
path: root/include/rpcd/session.h
blob: 8ff3ed0cd35f2fb13b8a36de0d9f338bf95f7b99 (plain)
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
/*
 * rpcd - UBUS RPC server
 *
 *   Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
 *   Copyright (C) 2013-2014 Jo-Philipp Wich <jow@openwrt.org>
 *
 * 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.
 */

#ifndef __RPC_SESSION_H
#define __RPC_SESSION_H

#include <ctype.h>
#include <fcntl.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

#include <libubox/avl.h>
#include <libubox/blobmsg_json.h>

#define RPC_SID_LEN	32
#define RPC_DEFAULT_SESSION_TIMEOUT	300
#define RPC_DEFAULT_SESSION_ID	"00000000000000000000000000000000"
#define RPC_SESSION_DIRECTORY	"/var/run/rpcd/sessions"
#define RPC_SESSION_ACL_DIR		INSTALL_PREFIX "/share/rpcd/acl.d"

extern char apply_sid[RPC_SID_LEN + 1];

struct rpc_session {
	struct avl_node avl;
	char id[RPC_SID_LEN + 1];

	struct uloop_timeout t;
	struct avl_tree data;
	struct avl_tree acls;

	int timeout;
};

struct rpc_session_data {
	struct avl_node avl;
	struct blob_attr attr[];
};

struct rpc_session_acl_scope {
	struct avl_node avl;
	struct avl_tree acls;
};

struct rpc_session_acl {
	struct avl_node avl;
	const char *object;
	const char *function;
	int sort_len;
};

int rpc_session_api_init(struct ubus_context *ctx);

bool rpc_session_access(const char *sid, const char *scope,
                        const char *object, const char *function);

struct rpc_session_cb {
	struct list_head list;
	void (*cb)(struct rpc_session *, void *);
	void *priv;
};

void rpc_session_create_cb(struct rpc_session_cb *cb);
void rpc_session_destroy_cb(struct rpc_session_cb *cb);

void rpc_session_freeze(void);
void rpc_session_thaw(void);

#endif