Commit 225e6ae1 authored by Yathindra Naik's avatar Yathindra Naik

Convert capabilities to suitable string format for xenstore clients.

- Xenstore transactions are communicated via string messages.
- Clients ask for permissions on particular nodes.
- With capabilities, we'll need to convert capabilities to permission
  strings that clients expect.
parent 40d05e5f
...@@ -276,6 +276,67 @@ bool domain_is_cap(struct connection *conn) ...@@ -276,6 +276,67 @@ bool domain_is_cap(struct connection *conn)
{ {
return (conn && conn->domain && conn->domain->cap_flag); return (conn && conn->domain && conn->domain->cap_flag);
} }
/* For a given node, iterate through the domain list.
Find out which domains has the reqd capabilities
to access this node.
*/
static char *caps_to_strings(struct node *node, unsigned int *len)
{
xc_dominfo_t dominfo;
struct domain *domain, *tmp;
struct xs_permissions perm;
char *strings = NULL;
char buffer[MAX_STRLEN(unsigned int) + 1];
*len = 0;
list_for_each_entry_safe(domain, tmp, &domains, list) {
if (xc_domain_getinfo(*xc_handle, domain->domid, 1,
&dominfo) == 1 &&
dominfo.domid == domain->domid) {
/* If domain has crashed or its shutdown then move on. */
if ((dominfo.crashed || dominfo.shutdown)
&& !domain->shutdown) {
domain->shutdown = 1;
continue;
}
if (!dominfo.dying)
continue;
/* Continue if this is not in cap mode. */
if (!dominfo.cap_flag)
continue;
}
/* Init the perm struct. */
perm[0].id = -1;
perm[0].perms = XS_PERM_NONE;
/* Check if this domain has the reqd capability. */
if (xc_cap_check(domain->domid, node->cap[0]))
{
perm[0].id = domain->domid;
perm[0].perms = XS_PERM_READ;
}
/* Check if this domain has the write capability. */
if (xc_cap_check(domain->domid, node->cap[1]))
{
perm[0].id = domain->domid;
perm[0].perms |= XS_PERM_WRITE;
}
if (!xs_perm_to_string(&perms, buffer, sizeof(buffer)))
return NULL;
strings = talloc_realloc(ctx, strings, char,
*len + strlen(buffer) + 1);
strcpy(strings + *len, buffer);
*len += strlen(buffer) + 1;
}
return strings;
}
#endif #endif
bool domain_can_write(struct connection *conn) bool domain_can_write(struct connection *conn)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment