audit: use macros for unset inode and device values

Clean up a number of places were casted magic numbers are used to represent
unset inode and device numbers in preparation for the audit by executable path
patch set.

Signed-off-by: Richard Guy Briggs <rgb@redhat.com>
[PM: enclosed the _UNSET macros in parentheses for ./scripts/checkpatch]
Signed-off-by: Paul Moore <pmoore@redhat.com>
This commit is contained in:
Richard Guy Briggs 2015-08-05 23:48:20 -04:00 committed by Paul Moore
parent 8c85fc9ae6
commit 84cb777e67
4 changed files with 11 additions and 8 deletions

View File

@ -27,6 +27,9 @@
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <uapi/linux/audit.h> #include <uapi/linux/audit.h>
#define AUDIT_INO_UNSET ((unsigned long)-1)
#define AUDIT_DEV_UNSET ((dev_t)-1)
struct audit_sig_info { struct audit_sig_info {
uid_t uid; uid_t uid;
pid_t pid; pid_t pid;

View File

@ -1759,7 +1759,7 @@ void audit_log_name(struct audit_context *context, struct audit_names *n,
} else } else
audit_log_format(ab, " name=(null)"); audit_log_format(ab, " name=(null)");
if (n->ino != (unsigned long)-1) { if (n->ino != AUDIT_INO_UNSET) {
audit_log_format(ab, " inode=%lu" audit_log_format(ab, " inode=%lu"
" dev=%02x:%02x mode=%#ho" " dev=%02x:%02x mode=%#ho"
" ouid=%u ogid=%u rdev=%02x:%02x", " ouid=%u ogid=%u rdev=%02x:%02x",

View File

@ -138,7 +138,7 @@ char *audit_watch_path(struct audit_watch *watch)
int audit_watch_compare(struct audit_watch *watch, unsigned long ino, dev_t dev) int audit_watch_compare(struct audit_watch *watch, unsigned long ino, dev_t dev)
{ {
return (watch->ino != (unsigned long)-1) && return (watch->ino != AUDIT_INO_UNSET) &&
(watch->ino == ino) && (watch->ino == ino) &&
(watch->dev == dev); (watch->dev == dev);
} }
@ -179,8 +179,8 @@ static struct audit_watch *audit_init_watch(char *path)
INIT_LIST_HEAD(&watch->rules); INIT_LIST_HEAD(&watch->rules);
atomic_set(&watch->count, 1); atomic_set(&watch->count, 1);
watch->path = path; watch->path = path;
watch->dev = (dev_t)-1; watch->dev = AUDIT_DEV_UNSET;
watch->ino = (unsigned long)-1; watch->ino = AUDIT_INO_UNSET;
return watch; return watch;
} }
@ -493,7 +493,7 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
if (mask & (FS_CREATE|FS_MOVED_TO) && inode) if (mask & (FS_CREATE|FS_MOVED_TO) && inode)
audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0); audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0);
else if (mask & (FS_DELETE|FS_MOVED_FROM)) else if (mask & (FS_DELETE|FS_MOVED_FROM))
audit_update_watch(parent, dname, (dev_t)-1, (unsigned long)-1, 1); audit_update_watch(parent, dname, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF)) else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF))
audit_remove_parent_watches(parent); audit_remove_parent_watches(parent);

View File

@ -180,7 +180,7 @@ static int audit_match_filetype(struct audit_context *ctx, int val)
return 0; return 0;
list_for_each_entry(n, &ctx->names_list, list) { list_for_each_entry(n, &ctx->names_list, list) {
if ((n->ino != -1) && if ((n->ino != AUDIT_INO_UNSET) &&
((n->mode & S_IFMT) == mode)) ((n->mode & S_IFMT) == mode))
return 1; return 1;
} }
@ -1681,7 +1681,7 @@ static struct audit_names *audit_alloc_name(struct audit_context *context,
aname->should_free = true; aname->should_free = true;
} }
aname->ino = (unsigned long)-1; aname->ino = AUDIT_INO_UNSET;
aname->type = type; aname->type = type;
list_add_tail(&aname->list, &context->names_list); list_add_tail(&aname->list, &context->names_list);
@ -1923,7 +1923,7 @@ void __audit_inode_child(const struct inode *parent,
if (inode) if (inode)
audit_copy_inode(found_child, dentry, inode); audit_copy_inode(found_child, dentry, inode);
else else
found_child->ino = (unsigned long)-1; found_child->ino = AUDIT_INO_UNSET;
} }
EXPORT_SYMBOL_GPL(__audit_inode_child); EXPORT_SYMBOL_GPL(__audit_inode_child);