session: support reclaiming pending apply session
Reclaim the pending apply session upon login when the username matches the current login. This is required to support apply-confirm-rollback workflow for ubus browser clients, since changing IPs requires re-login to the device due to cross domain restrictions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
f0f6f81edb
commit
3d400c723b
3 changed files with 38 additions and 2 deletions
|
@ -36,6 +36,8 @@
|
||||||
#define RPC_SESSION_DIRECTORY "/var/run/rpcd/sessions"
|
#define RPC_SESSION_DIRECTORY "/var/run/rpcd/sessions"
|
||||||
#define RPC_SESSION_ACL_DIR "/usr/share/rpcd/acl.d"
|
#define RPC_SESSION_ACL_DIR "/usr/share/rpcd/acl.d"
|
||||||
|
|
||||||
|
extern char apply_sid[RPC_SID_LEN + 1];
|
||||||
|
|
||||||
struct rpc_session {
|
struct rpc_session {
|
||||||
struct avl_node avl;
|
struct avl_node avl;
|
||||||
char id[RPC_SID_LEN + 1];
|
char id[RPC_SID_LEN + 1];
|
||||||
|
|
35
session.c
35
session.c
|
@ -1085,6 +1085,31 @@ rpc_login_setup_acls(struct rpc_session *ses, struct uci_section *login)
|
||||||
globfree(&gl);
|
globfree(&gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct rpc_session *
|
||||||
|
rpc_reclaim_apply_session(const char *expected_username)
|
||||||
|
{
|
||||||
|
struct rpc_session_data *username;
|
||||||
|
struct rpc_session *ses;
|
||||||
|
|
||||||
|
if (!apply_sid[0])
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ses = rpc_session_get(apply_sid);
|
||||||
|
|
||||||
|
if (!ses)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
username = avl_find_element(&ses->data, "username", username, avl);
|
||||||
|
|
||||||
|
if (!username || blobmsg_type(username->attr) != BLOBMSG_TYPE_STRING)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (strcmp(blobmsg_get_string(username->attr), expected_username))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return ses;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rpc_handle_login(struct ubus_context *ctx, struct ubus_object *obj,
|
rpc_handle_login(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
struct ubus_request_data *req, const char *method,
|
struct ubus_request_data *req, const char *method,
|
||||||
|
@ -1122,7 +1147,15 @@ rpc_handle_login(struct ubus_context *ctx, struct ubus_object *obj,
|
||||||
if (tb[RPC_L_TIMEOUT])
|
if (tb[RPC_L_TIMEOUT])
|
||||||
timeout = blobmsg_get_u32(tb[RPC_L_TIMEOUT]);
|
timeout = blobmsg_get_u32(tb[RPC_L_TIMEOUT]);
|
||||||
|
|
||||||
ses = rpc_session_create(timeout);
|
/*
|
||||||
|
* attempt to reclaim a pending apply session, but only accept it
|
||||||
|
* if the username matches, otherwise perform a new login
|
||||||
|
*/
|
||||||
|
|
||||||
|
ses = rpc_reclaim_apply_session(blobmsg_get_string(tb[RPC_L_USERNAME]));
|
||||||
|
|
||||||
|
if (!ses)
|
||||||
|
ses = rpc_session_create(timeout);
|
||||||
|
|
||||||
if (!ses) {
|
if (!ses) {
|
||||||
rv = UBUS_STATUS_UNKNOWN_ERROR;
|
rv = UBUS_STATUS_UNKNOWN_ERROR;
|
||||||
|
|
3
uci.c
3
uci.c
|
@ -30,7 +30,8 @@ static struct blob_buf buf;
|
||||||
static struct uci_context *cursor;
|
static struct uci_context *cursor;
|
||||||
static struct uloop_timeout apply_timer;
|
static struct uloop_timeout apply_timer;
|
||||||
static struct ubus_context *apply_ctx;
|
static struct ubus_context *apply_ctx;
|
||||||
static char apply_sid[RPC_SID_LEN + 1];
|
|
||||||
|
char apply_sid[RPC_SID_LEN + 1];
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RPC_G_CONFIG,
|
RPC_G_CONFIG,
|
||||||
|
|
Loading…
Add table
Reference in a new issue