Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
apk-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
alpine
apk-tools
Commits
c39dacf2
Commit
c39dacf2
authored
11 years ago
by
Timo Teräs
Browse files
Options
Downloads
Patches
Plain Diff
audit: report missing files in system mode
fixes #2113
parent
065715a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/audit.c
+64
-21
64 additions, 21 deletions
src/audit.c
with
64 additions
and
21 deletions
src/audit.c
+
64
−
21
View file @
c39dacf2
...
@@ -21,6 +21,10 @@
...
@@ -21,6 +21,10 @@
#include
"apk_database.h"
#include
"apk_database.h"
#include
"apk_print.h"
#include
"apk_print.h"
/* Use (unused) highest bit of mode_t as seen flag of our internal
* database file entries */
#define S_SEENFLAG 0x80000000
enum
{
enum
{
MODE_BACKUP
=
0
,
MODE_BACKUP
=
0
,
MODE_SYSTEM
MODE_SYSTEM
...
@@ -78,6 +82,8 @@ static int audit_file(struct audit_ctx *actx,
...
@@ -78,6 +82,8 @@ static int audit_file(struct audit_ctx *actx,
if
(
dbf
==
NULL
)
if
(
dbf
==
NULL
)
return
'A'
;
return
'A'
;
dbf
->
mode
|=
S_SEENFLAG
;
if
(
apk_file_get_info
(
dirfd
,
name
,
APK_FI_NOFOLLOW
|
dbf
->
csum
.
type
,
&
fi
)
!=
0
)
if
(
apk_file_get_info
(
dirfd
,
name
,
APK_FI_NOFOLLOW
|
dbf
->
csum
.
type
,
&
fi
)
!=
0
)
return
-
EPERM
;
return
-
EPERM
;
...
@@ -104,6 +110,8 @@ static int audit_directory(struct audit_ctx *actx,
...
@@ -104,6 +110,8 @@ static int audit_directory(struct audit_ctx *actx,
struct
apk_db_dir
*
dbd
,
struct
apk_db_dir
*
dbd
,
struct
apk_file_info
*
fi
)
struct
apk_file_info
*
fi
)
{
{
if
(
dbd
!=
NULL
)
dbd
->
mode
|=
S_SEENFLAG
;
if
(
dbd
==
NULL
||
dbd
->
refs
==
1
)
if
(
dbd
==
NULL
||
dbd
->
refs
==
1
)
return
actx
->
recursive
?
'd'
:
'D'
;
return
actx
->
recursive
?
'd'
:
'D'
;
...
@@ -245,41 +253,76 @@ done:
...
@@ -245,41 +253,76 @@ done:
return
reason
<
0
?
reason
:
0
;
return
reason
<
0
?
reason
:
0
;
}
}
static
int
audit_directory_tree
(
struct
audit_tree_ctx
*
atctx
,
int
dirfd
)
{
apk_blob_t
path
;
int
r
;
path
=
APK_BLOB_PTR_LEN
(
atctx
->
path
,
atctx
->
pathlen
);
if
(
path
.
len
&&
path
.
ptr
[
path
.
len
-
1
]
==
'/'
)
path
.
len
--
;
atctx
->
dir
=
apk_db_dir_get
(
atctx
->
db
,
path
);
atctx
->
dir
->
mode
|=
S_SEENFLAG
;
r
=
apk_dir_foreach_file
(
dirfd
,
audit_directory_tree_item
,
atctx
);
apk_db_dir_unref
(
atctx
->
db
,
atctx
->
dir
,
FALSE
);
return
r
;
}
static
int
audit_missing_files
(
apk_hash_item
item
,
void
*
pctx
)
{
struct
audit_ctx
*
actx
=
pctx
;
struct
apk_db_file
*
file
=
item
;
struct
apk_db_dir
*
dir
;
char
path
[
PATH_MAX
];
int
len
;
if
(
file
->
mode
&
S_SEENFLAG
)
return
0
;
dir
=
file
->
diri
->
dir
;
if
(
dir
->
mode
&
S_SEENFLAG
)
{
len
=
snprintf
(
path
,
sizeof
(
path
),
DIR_FILE_FMT
,
DIR_FILE_PRINTF
(
dir
,
file
));
report_audit
(
actx
,
'X'
,
APK_BLOB_PTR_LEN
(
path
,
len
),
file
->
diri
->
pkg
);
}
return
0
;
}
static
int
audit_main
(
void
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
static
int
audit_main
(
void
*
ctx
,
struct
apk_database
*
db
,
struct
apk_string_array
*
args
)
{
{
struct
audit_tree_ctx
atctx
;
struct
audit_tree_ctx
atctx
;
struct
audit_ctx
*
actx
=
(
struct
audit_ctx
*
)
ctx
;
char
**
parg
,
*
arg
;
char
**
parg
,
*
arg
;
int
r
=
0
;
int
r
=
0
;
atctx
.
db
=
db
;
atctx
.
db
=
db
;
atctx
.
actx
=
(
struct
audit_ctx
*
)
ctx
;
atctx
.
actx
=
a
ctx
;
atctx
.
pathlen
=
0
;
atctx
.
pathlen
=
0
;
atctx
.
path
[
0
]
=
0
;
atctx
.
path
[
0
]
=
0
;
if
(
args
->
num
==
0
)
{
if
(
args
->
num
==
0
)
{
atctx
.
dir
=
apk_db_dir_get
(
db
,
APK_BLOB_PTR_LEN
(
atctx
.
path
,
atctx
.
pathlen
));
r
|=
audit_directory_tree
(
&
atctx
,
dup
(
db
->
root_fd
));
r
=
apk_dir_foreach_file
(
dup
(
db
->
root_fd
),
audit_directory_tree_item
,
&
atctx
);
}
else
{
apk_db_dir_unref
(
db
,
atctx
.
dir
,
FALSE
);
foreach_array_item
(
parg
,
args
)
{
return
r
;
arg
=
*
parg
;
}
if
(
arg
[
0
]
!=
'/'
)
{
apk_warning
(
"%s: relative path skipped.
\n
"
,
arg
);
continue
;
}
arg
++
;
atctx
.
pathlen
=
strlen
(
arg
);
memcpy
(
atctx
.
path
,
arg
,
atctx
.
pathlen
);
if
(
atctx
.
path
[
atctx
.
pathlen
-
1
]
!=
'/'
)
atctx
.
path
[
atctx
.
pathlen
++
]
=
'/'
;
foreach_array_item
(
parg
,
args
)
{
r
|=
audit_directory_tree
(
&
atctx
,
openat
(
db
->
root_fd
,
arg
,
O_RDONLY
|
O_CLOEXEC
));
arg
=
*
parg
;
if
(
arg
[
0
]
!=
'/'
)
{
apk_warning
(
"%s: relative path skipped.
\n
"
,
arg
);
continue
;
}
}
arg
++
;
atctx
.
pathlen
=
strlen
(
arg
);
memcpy
(
atctx
.
path
,
arg
,
atctx
.
pathlen
);
if
(
atctx
.
path
[
atctx
.
pathlen
-
1
]
!=
'/'
)
atctx
.
path
[
atctx
.
pathlen
++
]
=
'/'
;
atctx
.
dir
=
apk_db_dir_get
(
db
,
APK_BLOB_PTR_LEN
(
atctx
.
path
,
atctx
.
pathlen
));
r
|=
apk_dir_foreach_file
(
openat
(
db
->
root_fd
,
arg
,
O_RDONLY
|
O_CLOEXEC
),
audit_directory_tree_item
,
&
atctx
);
apk_db_dir_unref
(
db
,
atctx
.
dir
,
FALSE
);
}
}
if
(
actx
->
mode
==
MODE_SYSTEM
)
apk_hash_foreach
(
&
db
->
installed
.
files
,
audit_missing_files
,
ctx
);
return
r
;
return
r
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment