Made root node write and read own AA entries.

This commit is contained in:
Thomas Schmitt 2009-02-24 17:50:53 +01:00
parent 356b73eda8
commit 4daf626493
2 changed files with 104 additions and 50 deletions

View File

@ -2304,6 +2304,46 @@ int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts,
return ret;
}
/* Take over aa_string from file source to node or discard it after making
the necessary change in node->mode group permissions.
node->mode must already be set.
*/
static
int src_aa_to_node(IsoFileSource *src, IsoNode *node, int flag)
{
int ret;
unsigned char *aa_string;
ImageFileSourceData *data;
_ImageFsData *fsdata;
char *a_text = NULL, *d_text = NULL;
data = (ImageFileSourceData*)src->data;
fsdata = data->fs->data;
/* Obtain ownership of eventual AA string */
ret = iso_file_source_get_aa_string(src, &aa_string, 1);
if (ret != 1 || aa_string == NULL)
return 1;
if (fsdata->aaip_load == 1) {
/* Attach aa_string to node */
ret = iso_node_add_xinfo(node, aaip_xinfo_func, aa_string);
if (ret < 0)
return ret;
} else {
/* Look for ACL and perform S_IRWXG mapping */
iso_aa_get_acl_text(aa_string, node->mode, &a_text, &d_text, 16);
if (a_text != NULL)
aaip_cleanout_st_mode(a_text, &(node->mode), 4 | 16);
/* Dispose ACL a_text and d_text */
iso_aa_get_acl_text(aa_string, node->mode, &a_text, &d_text, 1 << 15);
/* Dispose aa_string */
aaip_xinfo_func(aa_string, 1);
}
return 1;
}
static
int image_builder_create_node(IsoNodeBuilder *builder, IsoImage *image,
IsoFileSource *src, IsoNode **node)
@ -2313,7 +2353,6 @@ int image_builder_create_node(IsoNodeBuilder *builder, IsoImage *image,
IsoNode *new;
char *name;
ImageFileSourceData *data;
unsigned char *aa_string;
if (builder == NULL || src == NULL || node == NULL || src->data == NULL) {
return ISO_NULL_POINTER;
@ -2483,33 +2522,17 @@ int image_builder_create_node(IsoNodeBuilder *builder, IsoImage *image,
new->parent = NULL;
new->next = NULL;
*node = new;
/* Obtain ownership of eventual AA string */
ret = iso_file_source_get_aa_string(src, &aa_string, 1);
if (ret == 1 && aa_string != NULL) {
_ImageFsData *fsdata = data->fs->data;
char *a_text = NULL, *d_text = NULL;
if (fsdata->aaip_load == 1) {
ret = iso_node_add_xinfo(new, aaip_xinfo_func, aa_string);
if (ret < 0)
return ret;
} else {
/* Look for ACL and perform S_IRWXG mapping */
if (aa_string != NULL)
iso_aa_get_acl_text(aa_string, info.st_mode, &a_text, &d_text,
16);
if (a_text != NULL)
aaip_cleanout_st_mode(a_text, &(new->mode), 4 | 16);
/* Dispose ACL a_text and d_text */
iso_aa_get_acl_text(aa_string, info.st_mode, &a_text, &d_text,
1 << 15);
/* Dispose aa_string */
aaip_xinfo_func(aa_string, 1);
}
ret = src_aa_to_node(src, new, 0);
if (ret < 0) {
/* todo: stuff any possible memory leak here */
if (name != NULL)
free(name);
free(new);
return ret;
}
*node = new;
return ISO_SUCCESS;
}
@ -2683,6 +2706,12 @@ int iso_image_import(IsoImage *image, IsoDataSource *src,
image->root->node.atime = info.st_atime;
image->root->node.mtime = info.st_mtime;
image->root->node.ctime = info.st_ctime;
/* This might fail in iso_node_add_xinfo() */
ret = src_aa_to_node(newroot, &(image->root->node), 0);
if (ret < 0)
goto import_revert;
}
/* if old image has el-torito, add a new catalog */

View File

@ -1038,6 +1038,37 @@ void susp_info_free(struct susp_info* susp)
free(susp->ce_susp_fields);
}
/* @param flag bit0= Do not add data but only count sua_free and ce_len
*/
static
int add_aa_string(Ecma119Image *t, Ecma119Node *n, struct susp_info *info,
size_t *sua_free, size_t *ce_len, int flag)
{
int ret;
uint8_t *aapt;
void *xipt;
size_t num_aapt= 0;
ret = iso_node_get_xinfo(n->node, aaip_xinfo_func, &xipt);
if (ret == 1) {
num_aapt = aaip_count_bytes((unsigned char *) xipt, 0);
if (num_aapt > 0) {
aapt = malloc(num_aapt);
if (aapt == NULL)
return ISO_OUT_OF_MEM;
memcpy(aapt, xipt, num_aapt);
ret = aaip_add_AA(t, info, &aapt, num_aapt, sua_free, ce_len,
flag & 1);
if (ret < 0)
return ret;
/* aapt is NULL now and the memory is owned by t */
}
}
return 1;
}
/**
* Fill a struct susp_info with the RR/SUSP entries needed for a given
* node.
@ -1063,12 +1094,10 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
Ecma119Node *node;
char *name = NULL;
char *dest = NULL;
uint8_t *aapt;
void *xipt;
size_t num_aapt= 0;
size_t aaip_er_len= 0;
size_t su_size_pd, ce_len_pd; /* predicted sizes of SUA and CA */
int ce_is_predicted = 0;
size_t aaip_sua_free= 0, aaip_len= 0;
if (t == NULL || n == NULL || info == NULL) {
return ISO_NULL_POINTER;
@ -1403,27 +1432,11 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
and write it to directory entry or CE area.
*/
ret = ISO_SUCCESS;
num_aapt = 0;
if (t->aaip) {
ret = iso_node_get_xinfo(n->node, aaip_xinfo_func, &xipt);
if (ret == 1) {
num_aapt = aaip_count_bytes((unsigned char *) xipt, 0);
if (num_aapt > 0) {
aapt = malloc(num_aapt);
if (aapt == NULL) {
ret = ISO_OUT_OF_MEM;
goto add_susp_cleanup;
}
memcpy(aapt, xipt, num_aapt);
ret = aaip_add_AA(t, info, &aapt, num_aapt,
&sua_free, &ce_len, 0);
if (ret < 0) {
goto add_susp_cleanup;
}
/* aapt is NULL now and the memory is owned by t */
}
}
ret = add_aa_string(t, n, info, &sua_free, &ce_len, 0);
if (ret < 0)
goto add_susp_cleanup;
}
} else {
@ -1447,7 +1460,14 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
aaip_er_len = 160;
}
ret = susp_add_CE(t, 182 + aaip_er_len, info);
/* Compute length of AAIP string of root node */
aaip_sua_free= 0;
ret = add_aa_string(t, n, info, &aaip_sua_free, &aaip_len, 1);
if (ret < 0)
goto add_susp_cleanup;
/* Allocate the necessary CE space */
ret = susp_add_CE(t, 182 + aaip_er_len + aaip_len, info);
/* 182 is RRIP-ER length */
if (ret < 0) {
goto add_susp_cleanup;
@ -1456,13 +1476,18 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
if (ret < 0) {
goto add_susp_cleanup;
}
if (t->aaip && !t->aaip_susp_1_10) {
ret = aaip_add_ER(t, info, 0);
if (ret < 0) {
goto add_susp_cleanup;
}
}
/* Write AAIP string of root node */
aaip_sua_free= aaip_len= 0;
ret = add_aa_string(t, n, info, &aaip_sua_free, &aaip_len, 0);
if (ret < 0)
goto add_susp_cleanup;
}
}