Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /trunk/1.6.x/ccs-patch/fs/tomoyo_audit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 265 - (show annotations) (download) (as text)
Tue Jun 5 11:19:48 2007 UTC (17 years ago) by kumaneko
Original Path: trunk/ccs-patch/fs/tomoyo_audit.c
File MIME type: text/x-csrc
File size: 4357 byte(s)
1.4.1
1 /*
2 * fs/tomoyo_audit.c
3 *
4 * Implementation of the Domain-Based Mandatory Access Control.
5 *
6 * Copyright (C) 2005-2007 NTT DATA CORPORATION
7 *
8 * Version: 1.4.1 2007/06/05
9 *
10 * This file is applicable to both 2.4.30 and 2.6.11 and later.
11 * See README.ccs for ChangeLog.
12 *
13 */
14 /***** TOMOYO Linux start. *****/
15
16 #include <linux/ccs_common.h>
17
18 /************************* AUDIT FUNCTIONS *************************/
19
20 static DECLARE_WAIT_QUEUE_HEAD(grant_log_wait);
21 static DECLARE_WAIT_QUEUE_HEAD(reject_log_wait);
22
23 static spinlock_t audit_log_lock = SPIN_LOCK_UNLOCKED;
24
25 struct log_entry {
26 struct list_head list;
27 char *log;
28 };
29
30 static LIST_HEAD(grant_log);
31 static LIST_HEAD(reject_log);
32
33 static int grant_log_count = 0, reject_log_count = 0;
34
35 char *InitAuditLog(int *len)
36 {
37 char *buf;
38 struct timeval tv;
39 struct task_struct *task = current;
40 const char *domainname = current->domain_info->domainname->name;
41 do_gettimeofday(&tv);
42 *len += strlen(domainname) + 256;
43 if ((buf = ccs_alloc(*len)) != NULL) snprintf(buf, (*len) - 1, "#timestamp=%lu pid=%d uid=%d gid=%d euid=%d egid=%d suid=%d sgid=%d fsuid=%d fsgid=%d\n%s\n", tv.tv_sec, task->pid, task->uid, task->gid, task->euid, task->egid, task->suid, task->sgid, task->fsuid, task->fsgid, domainname);
44 return buf;
45 }
46
47 static unsigned int GetMaxGrantLog(void)
48 {
49 return CheckCCSFlags(CCS_TOMOYO_MAX_GRANT_LOG);
50 }
51
52 static unsigned int GetMaxRejectLog(void)
53 {
54 return CheckCCSFlags(CCS_TOMOYO_MAX_REJECT_LOG);
55 }
56
57 /*
58 * Write audit log.
59 * Caller must allocate buf with InitAuditLog().
60 */
61 int WriteAuditLog(char *buf, const int is_granted)
62 {
63 struct log_entry *new_entry = ccs_alloc(sizeof(*new_entry));
64 if (!new_entry) goto out;
65 INIT_LIST_HEAD(&new_entry->list);
66 new_entry->log = buf;
67 /***** CRITICAL SECTION START *****/
68 spin_lock(&audit_log_lock);
69 if (is_granted) {
70 if (grant_log_count < GetMaxGrantLog()) {
71 list_add_tail(&new_entry->list, &grant_log);
72 grant_log_count++;
73 buf = NULL;
74 UpdateCounter(CCS_UPDATES_COUNTER_GRANT_LOG);
75 }
76 } else {
77 if (reject_log_count < GetMaxRejectLog()) {
78 list_add_tail(&new_entry->list, &reject_log);
79 reject_log_count++;
80 buf = NULL;
81 UpdateCounter(CCS_UPDATES_COUNTER_REJECT_LOG);
82 }
83 }
84 spin_unlock(&audit_log_lock);
85 /***** CRITICAL SECTION END *****/
86 if (is_granted) wake_up(&grant_log_wait);
87 else wake_up(&reject_log_wait);
88 if (!buf) return 0;
89 ccs_free(new_entry);
90 out: ;
91 ccs_free(buf);
92 return -ENOMEM;
93 }
94
95 int CanSaveAuditLog(const int is_granted)
96 {
97 if (is_granted) {
98 if (grant_log_count < GetMaxGrantLog()) return 0;
99 } else {
100 if (reject_log_count < GetMaxRejectLog()) return 0;
101 }
102 return -ENOMEM;
103 }
104
105 int ReadGrantLog(struct io_buffer *head)
106 {
107 struct log_entry *ptr = NULL;
108 if (head->read_avail) return 0;
109 if (head->read_buf) {
110 ccs_free(head->read_buf); head->read_buf = NULL;
111 head->readbuf_size = 0;
112 }
113 /***** CRITICAL SECTION START *****/
114 spin_lock(&audit_log_lock);
115 if (!list_empty(&grant_log)) {
116 ptr = list_entry(grant_log.next, struct log_entry, list);
117 list_del(&ptr->list);
118 grant_log_count--;
119 }
120 spin_unlock(&audit_log_lock);
121 /***** CRITICAL SECTION END *****/
122 if (ptr) {
123 head->read_buf = ptr->log;
124 head->readbuf_size = head->read_avail = strlen(ptr->log) + 1;
125 ccs_free(ptr);
126 }
127 return 0;
128 }
129
130 int PollGrantLog(struct file *file, poll_table *wait)
131 {
132 if (grant_log_count) return POLLIN | POLLRDNORM;
133 poll_wait(file, &grant_log_wait, wait);
134 if (grant_log_count) return POLLIN | POLLRDNORM;
135 return 0;
136 }
137
138 int ReadRejectLog(struct io_buffer *head)
139 {
140 struct log_entry *ptr = NULL;
141 if (head->read_avail) return 0;
142 if (head->read_buf) {
143 ccs_free(head->read_buf); head->read_buf = NULL;
144 head->readbuf_size = 0;
145 }
146 /***** CRITICAL SECTION START *****/
147 spin_lock(&audit_log_lock);
148 if (!list_empty(&reject_log)) {
149 ptr = list_entry(reject_log.next, struct log_entry, list);
150 list_del(&ptr->list);
151 reject_log_count--;
152 }
153 spin_unlock(&audit_log_lock);
154 /***** CRITICAL SECTION END *****/
155 if (ptr) {
156 head->read_buf = ptr->log;
157 head->readbuf_size = head->read_avail = strlen(ptr->log) + 1;
158 ccs_free(ptr);
159 }
160 return 0;
161 }
162
163 int PollRejectLog(struct file *file, poll_table *wait)
164 {
165 if (reject_log_count) return POLLIN | POLLRDNORM;
166 poll_wait(file, &reject_log_wait, wait);
167 if (reject_log_count) return POLLIN | POLLRDNORM;
168 return 0;
169 }
170
171 /***** TOMOYO Linux end. *****/

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26