1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/smfs/audit_mds.c
5 * Lustre filesystem audit part for MDS
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_SM
30 #include <linux/kmod.h>
31 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/obd_class.h>
35 #include <linux/obd.h>
36 #include <linux/lustre_lib.h>
37 #include <linux/lustre_log.h>
38 #include <linux/lustre_fsfilt.h>
39 #include <linux/lustre_smfs.h>
40 #include <linux/lustre_audit.h>
41 #include "smfs_internal.h"
43 static int audit_ost_get_id(struct inode * inode, struct lustre_id * id)
45 struct fsfilt_operations *fsfilt = S2SMI(inode->i_sb)->sm_fsfilt;
48 if(fsfilt->fs_get_md(inode, id, sizeof(*id), EA_SID) <= 0)
54 static int audit_ost_create_rec(struct inode * parent, void * arg,
55 struct audit_priv * priv, char * buffer,
58 struct hook_msg * msg = arg;
59 struct audit_record * rec = (void*)buffer;
60 char * pbuf = buffer + sizeof(*rec);
61 struct inode * inode = msg->dentry->d_inode;
63 int len = sizeof(*rec);
65 if (audit_ost_get_id(inode, &id) < 0)
66 CERROR("Cannot get lustre id from object EA\n");
68 rec->opcode = AUDIT_CREATE;
69 len += audit_rec_from_id(&pbuf, &id);
70 *type = SMFS_AUDIT_GEN_REC;
74 static int audit_ost_unlink_rec(struct inode * parent, void * arg,
75 struct audit_priv * priv, char * buffer,
78 struct hook_unlink_msg * msg = arg;
79 struct inode * inode = msg->dentry->d_inode;
80 struct audit_record * rec = (void*)buffer;
81 char * pbuf = buffer + sizeof(*rec);
82 int len = sizeof(*rec);
85 if (audit_ost_get_id(inode, &id) < 0)
86 CERROR("Cannot get lustre id from object EA\n");
88 rec->opcode = AUDIT_UNLINK;
89 len += audit_rec_from_id(&pbuf, &id);
90 //len += audit_fill_id_rec(&pbuf, parent);
91 *type = SMFS_AUDIT_GEN_REC;
96 int static audit_ost_setattr_rec(struct inode * inode, void * arg,
97 struct audit_priv * priv, char * buffer,
100 //struct hook_attr_msg * msg = arg;
101 struct audit_record * rec = (void*)buffer;
102 char * pbuf = buffer + sizeof(*rec);
103 int len = sizeof(*rec);
106 if (audit_ost_get_id(inode, &id) < 0)
107 CERROR("Cannot get lustre id from object EA\n");
109 rec->opcode = AUDIT_SETATTR;
110 len += audit_rec_from_id(&pbuf, &id);
111 *type = SMFS_AUDIT_GEN_REC;
116 int static audit_ost_rw_rec(struct inode * inode, void * arg,
117 struct audit_priv * priv, char * buffer,
120 struct hook_rw_msg * msg = arg;
121 struct audit_record * rec = (void*)buffer;
122 char * pbuf = buffer + sizeof(*rec);
123 int len = sizeof(*rec);
126 if (audit_ost_get_id(inode, &id) < 0)
127 CERROR("Cannot get lustre id from object EA\n");
129 rec->opcode = msg->write ? AUDIT_WRITE : AUDIT_READ;
130 len += audit_rec_from_id(&pbuf, &id);
131 *type = SMFS_AUDIT_GEN_REC;
136 static audit_get_op audit_ost_record[HOOK_MAX] = {
137 [HOOK_SI_READ] audit_ost_rw_rec,
138 [HOOK_SI_WRITE] audit_ost_rw_rec,
139 [HOOK_READ] audit_ost_rw_rec,
140 [HOOK_WRITE] audit_ost_rw_rec,
141 [HOOK_CREATE] NULL, /* audit_ost_create_rec, */
142 [HOOK_UNLINK] NULL, //audit_ost_unlink_rec,
143 [HOOK_SETATTR] NULL, //audit_ost_setattr_rec,
144 [HOOK_F_SETATTR] NULL, //audit_ost_setattr_rec
147 int audit_ost_setup(struct obd_device * obd, struct super_block *sb,
148 struct audit_priv *priv)
151 struct smfs_super_info * smb = S2SMI(sb);
152 struct llog_ctxt **ctxt = &priv->audit_ctxt;
154 //this will do OBD_ALLOC() for ctxt
155 rc = llog_catalog_setup(ctxt, AUDIT_OST_NAME, smb->smsi_exp,
156 smb->smsi_ctxt, smb->sm_fsfilt,
157 smb->smsi_logs_dir, smb->smsi_objects_dir);
159 /* export audit llog ctxt */
161 (*ctxt)->loc_idx = LLOG_AUDIT_ORIG_CTXT;
162 (*ctxt)->loc_obd = obd;
163 (*ctxt)->loc_llogs = &obd->obd_llogs;
164 (*ctxt)->loc_llogs->llog_ctxt[LLOG_AUDIT_ORIG_CTXT] = *ctxt;
167 priv->audit_get_record = audit_ost_record;