5 |
* |
* |
6 |
* Copyright (C) 2005-2007 NTT DATA CORPORATION |
* Copyright (C) 2005-2007 NTT DATA CORPORATION |
7 |
* |
* |
8 |
* Version: 1.4.2 2007/07/13 |
* Version: 1.5.0 2007/09/20 |
9 |
* |
* |
10 |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
* This file is applicable to both 2.4.30 and 2.6.11 and later. |
11 |
* See README.ccs for ChangeLog. |
* See README.ccs for ChangeLog. |
47 |
u8 is_deleted; |
u8 is_deleted; |
48 |
u8 is_not; |
u8 is_not; |
49 |
u8 is_last_name; |
u8 is_last_name; |
|
u8 is_oldstyle; |
|
50 |
}; |
}; |
51 |
|
|
52 |
/***** The structure for domains to not to transit domains. *****/ |
/***** The structure for domains to not to transit domains. *****/ |
85 |
|
|
86 |
/************************* UTILITY FUNCTIONS *************************/ |
/************************* UTILITY FUNCTIONS *************************/ |
87 |
|
|
|
int IsDomainDef(const unsigned char *buffer) |
|
|
{ |
|
|
/* while (*buffer && (*buffer <= ' ' || *buffer >= 127)) buffer++; */ |
|
|
return strncmp(buffer, ROOT_NAME, ROOT_NAME_LEN) == 0; |
|
|
} |
|
|
|
|
88 |
const char *GetLastName(const struct domain_info *domain) |
const char *GetLastName(const struct domain_info *domain) |
89 |
{ |
{ |
90 |
const char *cp0 = domain->domainname->name, *cp1; |
const char *cp0 = domain->domainname->name, *cp1; |
92 |
return cp0; |
return cp0; |
93 |
} |
} |
94 |
|
|
|
int ReadSelfDomain(struct io_buffer *head) |
|
|
{ |
|
|
if (!head->read_eof) { |
|
|
io_printf(head, "%s", current->domain_info->domainname->name); |
|
|
head->read_eof = 1; |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
95 |
int AddDomainACL(struct acl_info *ptr, struct domain_info *domain, struct acl_info *new_ptr) |
int AddDomainACL(struct acl_info *ptr, struct domain_info *domain, struct acl_info *new_ptr) |
96 |
{ |
{ |
97 |
mb(); /* Instead of using spinlock. */ |
mb(); /* Instead of using spinlock. */ |
114 |
for (ptr = domain->first_acl_ptr; ptr; ptr = ptr->next) { |
for (ptr = domain->first_acl_ptr; ptr; ptr = ptr->next) { |
115 |
if (!ptr->is_deleted) count++; |
if (!ptr->is_deleted) count++; |
116 |
} |
} |
117 |
/* If there are so many entries, don't append if accept mode. */ |
/* If there are so many entries, don't append if learning mode. */ |
118 |
if (count < CheckCCSFlags(CCS_TOMOYO_MAX_ACCEPT_ENTRY)) return 0; |
if (count < CheckCCSFlags(CCS_TOMOYO_MAX_ACCEPT_ENTRY)) return 0; |
119 |
if (!domain->quota_warned) { |
if (!domain->quota_warned) { |
120 |
printk("TOMOYO-WARNING: Domain '%s' has so many ACLs to hold. Stopped auto-append mode.\n", domain->domainname->name); |
printk("TOMOYO-WARNING: Domain '%s' has so many ACLs to hold. Stopped learning mode.\n", domain->domainname->name); |
121 |
domain->quota_warned = 1; |
domain->quota_warned = 1; |
122 |
} |
} |
123 |
return 1; |
return 1; |
128 |
|
|
129 |
static struct domain_initializer_entry *domain_initializer_list = NULL; |
static struct domain_initializer_entry *domain_initializer_list = NULL; |
130 |
|
|
131 |
static int AddDomainInitializerEntry(const char *domainname, const char *program, const int is_not, const int is_delete, const int is_oldstyle) |
static int AddDomainInitializerEntry(const char *domainname, const char *program, const int is_not, const int is_delete) |
132 |
{ |
{ |
133 |
struct domain_initializer_entry *new_entry, *ptr; |
struct domain_initializer_entry *new_entry, *ptr; |
134 |
static DECLARE_MUTEX(lock); |
static DECLARE_MUTEX(lock); |
147 |
if ((saved_program = SaveName(program)) == NULL) return -ENOMEM; |
if ((saved_program = SaveName(program)) == NULL) return -ENOMEM; |
148 |
down(&lock); |
down(&lock); |
149 |
for (ptr = domain_initializer_list; ptr; ptr = ptr->next) { |
for (ptr = domain_initializer_list; ptr; ptr = ptr->next) { |
150 |
if (ptr->is_not == is_not && ptr->is_oldstyle == is_oldstyle && ptr->domainname == saved_domainname && ptr->program == saved_program) { |
if (ptr->is_not == is_not && ptr->domainname == saved_domainname && ptr->program == saved_program) { |
151 |
ptr->is_deleted = is_delete; |
ptr->is_deleted = is_delete; |
152 |
error = 0; |
error = 0; |
153 |
goto out; |
goto out; |
162 |
new_entry->program = saved_program; |
new_entry->program = saved_program; |
163 |
new_entry->is_not = is_not; |
new_entry->is_not = is_not; |
164 |
new_entry->is_last_name = is_last_name; |
new_entry->is_last_name = is_last_name; |
|
new_entry->is_oldstyle = is_oldstyle; |
|
165 |
mb(); /* Instead of using spinlock. */ |
mb(); /* Instead of using spinlock. */ |
166 |
if ((ptr = domain_initializer_list) != NULL) { |
if ((ptr = domain_initializer_list) != NULL) { |
167 |
while (ptr->next) ptr = ptr->next; ptr->next = new_entry; |
while (ptr->next) ptr = ptr->next; ptr->next = new_entry; |
182 |
head->read_var2 = ptr; |
head->read_var2 = ptr; |
183 |
if (!ptr->is_deleted) { |
if (!ptr->is_deleted) { |
184 |
if (ptr->domainname) { |
if (ptr->domainname) { |
185 |
if (io_printf(head, "%s%s%s from %s\n", ptr->is_not ? "no_" : "", ptr->is_oldstyle ? KEYWORD_INITIALIZER : KEYWORD_INITIALIZE_DOMAIN, ptr->program->name, ptr->domainname->name)) break; |
if (io_printf(head, "%s" KEYWORD_INITIALIZE_DOMAIN "%s from %s\n", ptr->is_not ? "no_" : "", ptr->program->name, ptr->domainname->name)) break; |
186 |
} else { |
} else { |
187 |
if (io_printf(head, "%s%s%s\n", ptr->is_not ? "no_" : "", ptr->is_oldstyle ? KEYWORD_INITIALIZER : KEYWORD_INITIALIZE_DOMAIN, ptr->program->name)) break; |
if (io_printf(head, "%s" KEYWORD_INITIALIZE_DOMAIN "%s\n", ptr->is_not ? "no_" : "", ptr->program->name)) break; |
188 |
} |
} |
189 |
} |
} |
190 |
ptr = ptr->next; |
ptr = ptr->next; |
192 |
return ptr ? -ENOMEM : 0; |
return ptr ? -ENOMEM : 0; |
193 |
} |
} |
194 |
|
|
195 |
int AddDomainInitializerPolicy(char *data, const int is_not, const int is_delete, const int is_oldstyle) |
int AddDomainInitializerPolicy(char *data, const int is_not, const int is_delete) |
196 |
{ |
{ |
197 |
char *cp = strstr(data, " from "); |
char *cp = strstr(data, " from "); |
198 |
if (cp) { |
if (cp) { |
199 |
*cp = '\0'; |
*cp = '\0'; |
200 |
return AddDomainInitializerEntry(cp + 6, data, is_not, is_delete, is_oldstyle); |
return AddDomainInitializerEntry(cp + 6, data, is_not, is_delete); |
201 |
} else { |
} else { |
202 |
return AddDomainInitializerEntry(NULL, data, is_not, is_delete, is_oldstyle); |
return AddDomainInitializerEntry(NULL, data, is_not, is_delete); |
203 |
} |
} |
204 |
} |
} |
205 |
|
|
520 |
|
|
521 |
/************************* DOMAIN TRANSITION HANDLER *************************/ |
/************************* DOMAIN TRANSITION HANDLER *************************/ |
522 |
|
|
|
struct domain_info *FindDomain(const char *domainname0) |
|
|
{ |
|
|
struct domain_info *domain; |
|
|
static int first = 1; |
|
|
struct path_info domainname; |
|
|
domainname.name = domainname0; |
|
|
fill_path_info(&domainname); |
|
|
if (first) { |
|
|
KERNEL_DOMAIN.domainname = SaveName(ROOT_NAME); |
|
|
first = 0; |
|
|
} |
|
|
for (domain = &KERNEL_DOMAIN; domain; domain = domain->next) { |
|
|
if (!domain->is_deleted && !pathcmp(&domainname, domain->domainname)) return domain; |
|
|
} |
|
|
return NULL; |
|
|
} |
|
|
|
|
523 |
struct domain_info *FindOrAssignNewDomain(const char *domainname, const u8 profile) |
struct domain_info *FindOrAssignNewDomain(const char *domainname, const u8 profile) |
524 |
{ |
{ |
525 |
struct domain_info *domain = NULL; |
struct domain_info *domain = NULL; |
661 |
*/ |
*/ |
662 |
static int first = 1; |
static int first = 1; |
663 |
if (first) { |
if (first) { |
664 |
AddDomainInitializerEntry(NULL, "/sbin/hotplug", 0, 0, 0); |
AddDomainInitializerEntry(NULL, "/sbin/hotplug", 0, 0); |
665 |
AddDomainInitializerEntry(NULL, "/sbin/modprobe", 0, 0, 0); |
AddDomainInitializerEntry(NULL, "/sbin/modprobe", 0, 0); |
666 |
first = 0; |
first = 0; |
667 |
} |
} |
668 |
} |
} |