5 |
* |
* |
6 |
* Copyright (C) 2005-2007 NTT DATA CORPORATION |
* Copyright (C) 2005-2007 NTT DATA CORPORATION |
7 |
* |
* |
8 |
* Version: 1.5.2-pre 2007/11/19 |
* Version: 1.5.2-pre 2007/11/27 |
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. |
27 |
/***** The structure for chroot restrictions. *****/ |
/***** The structure for chroot restrictions. *****/ |
28 |
|
|
29 |
struct chroot_entry { |
struct chroot_entry { |
30 |
struct list_head list; |
struct list1_head list; |
31 |
const struct path_info *dir; |
const struct path_info *dir; |
32 |
bool is_deleted; |
bool is_deleted; |
33 |
}; |
}; |
34 |
|
|
35 |
/************************* CHROOT RESTRICTION HANDLER *************************/ |
/************************* CHROOT RESTRICTION HANDLER *************************/ |
36 |
|
|
37 |
static LIST_HEAD(chroot_list); |
static LIST1_HEAD(chroot_list); |
38 |
|
|
39 |
static int AddChrootACL(const char *dir, const bool is_delete) |
static int AddChrootACL(const char *dir, const bool is_delete) |
40 |
{ |
{ |
45 |
if (!IsCorrectPath(dir, 1, 0, 1, __FUNCTION__)) return -EINVAL; |
if (!IsCorrectPath(dir, 1, 0, 1, __FUNCTION__)) return -EINVAL; |
46 |
if ((saved_dir = SaveName(dir)) == NULL) return -ENOMEM; |
if ((saved_dir = SaveName(dir)) == NULL) return -ENOMEM; |
47 |
mutex_lock(&lock); |
mutex_lock(&lock); |
48 |
list_for_each_entry(ptr, &chroot_list, list) { |
list1_for_each_entry(ptr, &chroot_list, list) { |
49 |
if (ptr->dir == saved_dir) { |
if (ptr->dir == saved_dir) { |
50 |
ptr->is_deleted = is_delete; |
ptr->is_deleted = is_delete; |
51 |
error = 0; |
error = 0; |
58 |
} |
} |
59 |
if ((new_entry = alloc_element(sizeof(*new_entry))) == NULL) goto out; |
if ((new_entry = alloc_element(sizeof(*new_entry))) == NULL) goto out; |
60 |
new_entry->dir = saved_dir; |
new_entry->dir = saved_dir; |
61 |
list_add_tail_mb(&new_entry->list, &chroot_list); |
list1_add_tail_mb(&new_entry->list, &chroot_list); |
62 |
error = 0; |
error = 0; |
63 |
printk("%sAllow chroot() to %s\n", ccs_log_level, dir); |
printk("%sAllow chroot() to %s\n", ccs_log_level, dir); |
64 |
out: |
out: |
78 |
fill_path_info(&dir); |
fill_path_info(&dir); |
79 |
if (dir.is_dir) { |
if (dir.is_dir) { |
80 |
struct chroot_entry *ptr; |
struct chroot_entry *ptr; |
81 |
list_for_each_entry(ptr, &chroot_list, list) { |
list1_for_each_entry(ptr, &chroot_list, list) { |
82 |
if (ptr->is_deleted) continue; |
if (ptr->is_deleted) continue; |
83 |
if (PathMatchesToPattern(&dir, ptr->dir)) { |
if (PathMatchesToPattern(&dir, ptr->dir)) { |
84 |
error = 0; |
error = 0; |
111 |
|
|
112 |
int ReadChrootPolicy(struct io_buffer *head) |
int ReadChrootPolicy(struct io_buffer *head) |
113 |
{ |
{ |
114 |
struct list_head *pos; |
struct list1_head *pos; |
115 |
list_for_each_cookie(pos, head->read_var2, &chroot_list) { |
list1_for_each_cookie(pos, head->read_var2, &chroot_list) { |
116 |
struct chroot_entry *ptr; |
struct chroot_entry *ptr; |
117 |
ptr = list_entry(pos, struct chroot_entry, list); |
ptr = list1_entry(pos, struct chroot_entry, list); |
118 |
if (ptr->is_deleted) continue; |
if (ptr->is_deleted) continue; |
119 |
if (io_printf(head, KEYWORD_ALLOW_CHROOT "%s\n", ptr->dir->name)) return -ENOMEM; |
if (io_printf(head, KEYWORD_ALLOW_CHROOT "%s\n", ptr->dir->name)) return -ENOMEM; |
120 |
} |
} |