mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 22:35:35 +00:00
Finish adding support to allow the parser to loaded dumped profiles
generated using apparmor_parser profile -S >binary_profile can now be loaded using apparmor_parser -B binary_profile
This commit is contained in:
@@ -887,11 +887,30 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* bleah the kernel should just loop and do multiple load, but to support
|
||||||
|
* older systems we need to do this
|
||||||
|
*/
|
||||||
|
#define PROFILE_HEADER_SIZE
|
||||||
|
static char header_version[] = "\x04\x08\x00version";
|
||||||
|
|
||||||
|
static char *next_profile_buffer(char *buffer, int size)
|
||||||
|
{
|
||||||
|
char *b = buffer;
|
||||||
|
|
||||||
|
for (; size - sizeof(header_version); b++, size--) {
|
||||||
|
if (memcmp(b, header_version, sizeof(header_version)) == 0) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int sd_load_buffer(int option, char *buffer, int size)
|
int sd_load_buffer(int option, char *buffer, int size)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int error = 0, wsize;
|
int error = 0, wsize, bsize;
|
||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
|
char *b;
|
||||||
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case OPTION_ADD:
|
case OPTION_ADD:
|
||||||
@@ -915,12 +934,15 @@ int sd_load_buffer(int option, char *buffer, int size)
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
wsize = write(fd, buffer, size);
|
for (b = buffer; b ; b = next_profile_buffer(b + sizeof(header_version), bsize)) {
|
||||||
if (wsize < 0) {
|
bsize = size - (b - buffer);
|
||||||
error = -errno;
|
wsize = write(fd, b, bsize);
|
||||||
} else if (wsize < size) {
|
if (wsize < 0) {
|
||||||
PERROR(_("%s: Unable to write entire profile entry\n"),
|
error = -errno;
|
||||||
progname);
|
} else if (wsize < bsize) {
|
||||||
|
PERROR(_("%s: Unable to write entire profile entry\n"),
|
||||||
|
progname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
exit:
|
exit:
|
||||||
|
Reference in New Issue
Block a user