Userspace: handle the class field in role_trans struct

Add the class support to various functions that handle role_trans
structure.

Signed-off-by: Harry Ciao <qingtao.cao@windriver.com>
Signed-off-by: Steve Lawrence <slawrence@tresys.com>
This commit is contained in:
Harry Ciao 2011-03-25 13:52:01 +08:00 committed by Steve Lawrence
parent e95f358e3b
commit 93417dfa28
2 changed files with 32 additions and 4 deletions

View File

@ -2124,12 +2124,15 @@ static int type_read(policydb_t * p
return -1;
}
int role_trans_read(role_trans_t ** t, struct policy_file *fp)
int role_trans_read(policydb_t *p, struct policy_file *fp)
{
role_trans_t **t = &p->role_tr;
unsigned int i;
uint32_t buf[3], nel;
role_trans_t *tr, *ltr;
int rc;
int new_roletr = (p->policy_type == POLICY_KERN &&
p->policyvers >= POLICYDB_VERSION_ROLETRANS);
rc = next_entry(buf, fp, sizeof(uint32_t));
if (rc < 0)
@ -2152,6 +2155,13 @@ int role_trans_read(role_trans_t ** t, struct policy_file *fp)
tr->role = le32_to_cpu(buf[0]);
tr->type = le32_to_cpu(buf[1]);
tr->new_role = le32_to_cpu(buf[2]);
if (new_roletr) {
rc = next_entry(buf, fp, sizeof(uint32_t));
if (rc < 0)
return -1;
tr->tclass = le32_to_cpu(buf[0]);
} else
tr->tclass = SECCLASS_PROCESS;
ltr = tr;
}
return 0;
@ -3472,7 +3482,7 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
if (r_policyvers >= POLICYDB_VERSION_BOOL)
if (cond_read_list(p, &p->cond_list, fp))
goto bad;
if (role_trans_read(&p->role_tr, fp))
if (role_trans_read(p, fp))
goto bad;
if (role_allow_read(&p->role_allow, fp))
goto bad;

View File

@ -462,11 +462,15 @@ static int cat_write(hashtab_key_t key, hashtab_datum_t datum, void *ptr)
return POLICYDB_SUCCESS;
}
static int role_trans_write(role_trans_t * r, struct policy_file *fp)
static int role_trans_write(policydb_t *p, struct policy_file *fp)
{
role_trans_t *r = p->role_tr;
role_trans_t *tr;
uint32_t buf[3];
size_t nel, items;
int new_roletr = (p->policy_type == POLICY_KERN &&
p->policyvers >= POLICYDB_VERSION_ROLETRANS);
int warning_issued = 0;
nel = 0;
for (tr = r; tr; tr = tr->next)
@ -476,12 +480,26 @@ static int role_trans_write(role_trans_t * r, struct policy_file *fp)
if (items != 1)
return POLICYDB_ERROR;
for (tr = r; tr; tr = tr->next) {
if (!new_roletr && tr->tclass != SECCLASS_PROCESS) {
if (!warning_issued)
WARN(fp->handle, "Discarding role_transition "
"rules for security classes other than "
"\"process\"");
warning_issued = 1;
continue;
}
buf[0] = cpu_to_le32(tr->role);
buf[1] = cpu_to_le32(tr->type);
buf[2] = cpu_to_le32(tr->new_role);
items = put_entry(buf, sizeof(uint32_t), 3, fp);
if (items != 3)
return POLICYDB_ERROR;
if (new_roletr) {
buf[0] = cpu_to_le32(tr->tclass);
items = put_entry(buf, sizeof(uint32_t), 1, fp);
if (items != 1)
return POLICYDB_ERROR;
}
}
return POLICYDB_SUCCESS;
@ -1815,7 +1833,7 @@ int policydb_write(policydb_t * p, struct policy_file *fp)
if (cond_write_list(p, p->cond_list, fp))
return POLICYDB_ERROR;
}
if (role_trans_write(p->role_tr, fp))
if (role_trans_write(p, fp))
return POLICYDB_ERROR;
if (role_allow_write(p->role_allow, fp))
return POLICYDB_ERROR;