Whamcloud - gitweb
current branches now use lnet from HEAD
[fs/lustre-release.git] / lustre / llite / llite_audit.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5  *   
6  *   osc_audit.c - audit code for client side.
7  *      
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #define DEBUG_SUBSYSTEM S_LLITE
25 #include <linux/module.h>
26 #include <linux/types.h>
27 #include <linux/random.h>
28 #include <linux/version.h>
29
30 #include <linux/lustre_lite.h>
31 #include <linux/lustre_ha.h>
32 #include <linux/lustre_dlm.h>
33 #include <linux/lprocfs_status.h>
34 #include <linux/lustre_acl.h>
35 #include <linux/lustre_audit.h>
36 #include "llite_internal.h"
37
38 //audit is set via obd_set_info() on mds
39 int ll_set_audit(struct inode * inode, __u64 arg)
40 {
41         struct audit_attr_msg msg;
42         struct obd_export * exp = ll_i2mdexp(inode);
43         struct ll_sb_info * sbi = ll_s2sbi(inode->i_sb);
44         struct ll_inode_info *lli = ll_i2info(inode);
45         int rc;
46
47         msg.attr = arg;
48         msg.id = lli->lli_id;
49         CDEBUG(D_INFO, "Set audit 0x%x for "DLID4"\n", (__u32)arg, OLID4(&lli->lli_id));
50         rc = obd_set_info(exp, 5, "audit", sizeof(msg), &msg);
51         
52         //if fs audit is being set for fs then pass attr to all OSS
53         if (IS_AUDIT_OP(arg, AUDIT_FS)) {
54                 sbi->ll_audit_mask = arg;
55                 exp = ll_i2dtexp(inode);
56                 rc = obd_set_info(exp, 5, "audit", sizeof(msg), &msg);
57         } else if (IS_AUDIT_OP(arg, AUDIT_SYNC) ||
58                    IS_AUDIT_OP(arg, AUDIT_NULL)) {
59                 exp = ll_i2dtexp(inode);
60                 rc = obd_set_info(exp, 5, "audit", sizeof(msg), &msg);
61         } else {
62                 lli->lli_audit_mask = arg;
63         }
64         return rc;
65 }
66
67 int ll_check_audit(struct inode * inode, audit_op op, int ret)
68 {
69         __u64 mask = 0;
70
71         LASSERT(op < AUDIT_MAX);
72         //check fs audit        
73         if (IS_AUDIT(ll_s2sbi(inode->i_sb)->ll_audit_mask)) {
74                 mask = ll_s2sbi(inode->i_sb)->ll_audit_mask;
75         }
76         else if (IS_AUDIT(ll_i2info(inode)->lli_audit_mask)) {
77                 mask = ll_i2info(inode)->lli_audit_mask;
78         }
79         else
80                 return 0;
81
82         //if audit is only for failures?
83         if (ret >= 0 && IS_AUDIT_OP(mask, AUDIT_FAIL))
84                 return 0;
85         
86         return (IS_AUDIT_OP(mask,op));
87 }
88 /*
89  * this function send audit record data to selected OST
90  * obd_set_info() RPC is using for this with key "auditlog"
91  */
92
93 int ll_audit_log (struct inode * inode, audit_op code, int ret)
94 {
95         struct audit_msg msg;
96         struct obd_export * exp = ll_i2dtexp(inode);
97         int rc = 0;
98         
99         if (ll_check_audit(inode, code, ret)) {
100                 msg.id = ll_i2info(inode)->lli_id;
101                 msg.code = code;
102                 msg.result = ret;
103                 msg.uid = current->uid;
104                 msg.gid = current->gid;
105                 msg.nid = 0;
106                 
107                 rc = obd_set_info(exp, 8, "auditlog", sizeof(msg), &msg);
108         }
109         
110         RETURN(rc);
111 }
112