]> Pileus Git - ~andy/linux/blobdiff - kernel/auditfilter.c
Merge remote-tracking branch 'asoc/topic/ak4535' into asoc-next
[~andy/linux] / kernel / auditfilter.c
index ff4011c19b13843dd443f28ab05b5d497c63445d..7f19f23d38a3347373ec00a629c6c0b39a8f770a 100644 (file)
@@ -1328,36 +1328,29 @@ int parent_len(const char *path)
        return p - path;
 }
 
-/* Compare given dentry name with last component in given path,
- * return of 0 indicates a match. */
-int audit_compare_dname_path(const char *dname, const char *path)
+/**
+ * audit_compare_dname_path - compare given dentry name with last component in
+ *                           given path. Return of 0 indicates a match.
+ * @dname:     dentry name that we're comparing
+ * @path:      full pathname that we're comparing
+ * @parentlen: length of the parent if known. Passing in AUDIT_NAME_FULL
+ *             here indicates that we must compute this value.
+ */
+int audit_compare_dname_path(const char *dname, const char *path, int parentlen)
 {
-       int dlen, plen;
+       int dlen, pathlen;
        const char *p;
 
-       if (!dname || !path)
-               return 1;
-
        dlen = strlen(dname);
-       plen = strlen(path);
-       if (plen < dlen)
+       pathlen = strlen(path);
+       if (pathlen < dlen)
                return 1;
 
-       /* disregard trailing slashes */
-       p = path + plen - 1;
-       while ((*p == '/') && (p > path))
-               p--;
-
-       /* find last path component */
-       p = p - dlen + 1;
-       if (p < path)
+       parentlen = parentlen == AUDIT_NAME_FULL ? parent_len(path) : parentlen;
+       if (pathlen - parentlen != dlen)
                return 1;
-       else if (p > path) {
-               if (*--p != '/')
-                       return 1;
-               else
-                       p++;
-       }
+
+       p = path + parentlen;
 
        return strncmp(p, dname, dlen);
 }