audit: make audit_compare_dname_path use parent_len helper
Signed-off-by: Eric Paris <eparis@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
563a0d1236
commit
29e9a3467c
1 changed files with 7 additions and 20 deletions
|
@ -1332,32 +1332,19 @@ int parent_len(const char *path)
|
||||||
* return of 0 indicates a match. */
|
* return of 0 indicates a match. */
|
||||||
int audit_compare_dname_path(const char *dname, const char *path)
|
int audit_compare_dname_path(const char *dname, const char *path)
|
||||||
{
|
{
|
||||||
int dlen, plen;
|
int dlen, pathlen, parentlen;
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if (!dname || !path)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
dlen = strlen(dname);
|
dlen = strlen(dname);
|
||||||
plen = strlen(path);
|
pathlen = strlen(path);
|
||||||
if (plen < dlen)
|
if (pathlen < dlen)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* disregard trailing slashes */
|
parentlen = parent_len(path);
|
||||||
p = path + plen - 1;
|
if (pathlen - parentlen != dlen)
|
||||||
while ((*p == '/') && (p > path))
|
return 1;
|
||||||
p--;
|
|
||||||
|
|
||||||
/* find last path component */
|
p = path + parentlen;
|
||||||
p = p - dlen + 1;
|
|
||||||
if (p < path)
|
|
||||||
return 1;
|
|
||||||
else if (p > path) {
|
|
||||||
if (*--p != '/')
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return strncmp(p, dname, dlen);
|
return strncmp(p, dname, dlen);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue