1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/mds/mds_audit.c
5 * Lustre Metadata Server (mds) audit stuff
7 * Copyright (c) 2001-2003 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.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_MDS
30 #include <linux/module.h>
31 #include <linux/lustre_mds.h>
32 #include <linux/lustre_dlm.h>
33 #include <linux/init.h>
34 #include <linux/obd_class.h>
35 #include <linux/random.h>
37 #include <linux/jbd.h>
38 #include <linux/namei.h>
39 #include <linux/ext3_fs.h>
40 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
41 # include <linux/smp_lock.h>
42 # include <linux/buffer_head.h>
43 # include <linux/workqueue.h>
44 # include <linux/mount.h>
46 # include <linux/locks.h>
48 #include <linux/obd_lov.h>
49 #include <linux/obd_ost.h>
50 #include <linux/lustre_mds.h>
51 #include <linux/lustre_fsfilt.h>
52 #include <linux/lprocfs_status.h>
53 #include <linux/lustre_commit_confd.h>
54 #include <linux/lustre_acl.h>
55 #include "mds_internal.h"
57 int mds_audit_stat(struct ptlrpc_request *req, struct lustre_id * id,
58 struct inode *inode, char *name, int namelen, int ret)
60 struct obd_device *obd = req->rq_export->exp_obd;
61 ptl_nid_t nid = req->rq_peer.peer_id.nid;
62 struct audit_info info = {
66 int rc = 0, len = sizeof(info);
74 info.m.uid = current->uid;
75 info.m.gid = current->gid;
77 info.m.code = AUDIT_STAT;
80 info.namelen = namelen;
82 // send info to local fs
83 fsfilt_set_info(obd, inode->i_sb, inode,
84 10, "audit_info", len, (void*)&info);
89 int mds_audit_open(struct ptlrpc_request *req, struct lustre_id * id,
90 struct inode *inode, char *name, int namelen, int ret)
92 struct obd_device *obd = req->rq_export->exp_obd;
93 ptl_nid_t nid = req->rq_peer.peer_id.nid;
94 struct audit_info info = {
98 int rc = 0, len = sizeof(info);
105 info.m.uid = current->uid;
106 info.m.gid = current->gid;
108 info.m.code = AUDIT_OPEN;
111 info.namelen = namelen;
114 fsfilt_set_info(obd, inode->i_sb, inode,
115 10, "audit_info", len, (void*)&info);
120 int mds_audit_auth(struct ptlrpc_request *req, struct lvfs_ucred * uc,
121 audit_op op, struct lustre_id * id,
122 char * name, int namelen)
124 struct obd_device *obd = req->rq_export->exp_obd;
125 ptl_nid_t nid = req->rq_peer.peer_id.nid;
127 struct dentry * dparent;
128 struct inode * inode;
129 struct audit_info info;
133 dparent = mds_id2dentry(obd, id, NULL);
134 if (IS_ERR(dparent)) {
135 rc = PTR_ERR(dparent);
138 inode = dparent->d_inode;
141 info.m.uid = uc->luc_uid;
142 info.m.gid = uc->luc_gid;
144 info.m.result = -EPERM;
147 info.namelen = namelen;
149 fsfilt_set_info(obd, inode->i_sb, inode,
150 10, "audit_info", sizeof(info), &info);
158 static int mds_set_obj_audit(struct obd_device * obd, struct inode * inode,
161 struct audit_lov_msg msg = {
172 len = fsfilt_get_md(obd, inode, NULL, 0, EA_LOV);
176 CERROR("error getting inode %lu LOV: %d\n", inode->i_ino, len);
178 } else if (len == 0) {
179 CDEBUG(D_INODE, "no LOV in inode %lu\n", inode->i_ino);
185 CERROR("can't allocate memory\n");
186 GOTO(out, rc = -ENOMEM);
190 rc = fsfilt_get_md(obd, inode, lmm, len, EA_LOV);
194 CERROR("error getting inode %lu MD: %d\n", inode->i_ino, rc);
198 rc = obd_unpackmd(obd->u.mds.mds_dt_exp, &msg.lsm, lmm, len);
200 CERROR("error unpacking inode %lu MD: %d\n", inode->i_ino, rc);
204 obd_set_info(obd->u.mds.mds_dt_exp, 9, "audit_obj", sizeof(msg), &msg);
208 obd_free_memmd(obd->u.mds.mds_dt_exp, &msg.lsm);
216 //set audit attributes for directory/file
217 int mds_set_audit(struct obd_device * obd, void * val)
219 struct inode * inode = NULL;
220 struct dentry * dentry = NULL;
221 //struct lvfs_run_ctxt saved;
222 struct audit_attr_msg * msg = val;
226 //push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
228 dentry = mds_id2dentry(obd, &msg->id, NULL);
229 if (IS_ERR(dentry)) {
230 CERROR("Cannot get dentry\n");
231 RETURN(PTR_ERR(dentry));
234 inode = dentry->d_inode;
235 fsfilt_set_info(obd, inode->i_sb, inode,
236 5, "audit", sizeof(msg->attr), &msg->attr);
238 if (S_ISREG(inode->i_mode) && !IS_AUDIT_OP(msg->attr, AUDIT_FS))
239 mds_set_obj_audit(obd, inode, &msg->attr);
243 //pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
248 int mds_pack_audit(struct obd_device * obd, struct inode * inode,
249 struct mds_body * body)
252 int len = sizeof(mask);
255 rc = fsfilt_get_info(obd, inode->i_sb, inode,
256 5, "audit", &len, &mask);
259 body->valid |= OBD_MD_FLAUDIT;