diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/devpts |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'fs/devpts')
-rw-r--r-- | fs/devpts/Makefile | 8 | ||||
-rw-r--r-- | fs/devpts/inode.c | 242 | ||||
-rw-r--r-- | fs/devpts/xattr_security.c | 47 |
3 files changed, 297 insertions, 0 deletions
diff --git a/fs/devpts/Makefile b/fs/devpts/Makefile new file mode 100644 index 000000000000..5800df2e50c8 --- /dev/null +++ b/fs/devpts/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # | ||
2 | # Makefile for the Linux /dev/pts virtual filesystem. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_UNIX98_PTYS) += devpts.o | ||
6 | |||
7 | devpts-$(CONFIG_UNIX98_PTYS) := inode.o | ||
8 | devpts-$(CONFIG_DEVPTS_FS_SECURITY) += xattr_security.o | ||
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c new file mode 100644 index 000000000000..1571c8d6c232 --- /dev/null +++ b/fs/devpts/inode.c | |||
@@ -0,0 +1,242 @@ | |||
1 | /* -*- linux-c -*- --------------------------------------------------------- * | ||
2 | * | ||
3 | * linux/fs/devpts/inode.c | ||
4 | * | ||
5 | * Copyright 1998-2004 H. Peter Anvin -- All Rights Reserved | ||
6 | * | ||
7 | * This file is part of the Linux kernel and is made available under | ||
8 | * the terms of the GNU General Public License, version 2, or at your | ||
9 | * option, any later version, incorporated herein by reference. | ||
10 | * | ||
11 | * ------------------------------------------------------------------------- */ | ||
12 | |||
13 | #include <linux/module.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/fs.h> | ||
16 | #include <linux/sched.h> | ||
17 | #include <linux/namei.h> | ||
18 | #include <linux/mount.h> | ||
19 | #include <linux/tty.h> | ||
20 | #include <linux/devpts_fs.h> | ||
21 | #include <linux/xattr.h> | ||
22 | |||
23 | #define DEVPTS_SUPER_MAGIC 0x1cd1 | ||
24 | |||
25 | extern struct xattr_handler devpts_xattr_security_handler; | ||
26 | |||
27 | static struct xattr_handler *devpts_xattr_handlers[] = { | ||
28 | #ifdef CONFIG_DEVPTS_FS_SECURITY | ||
29 | &devpts_xattr_security_handler, | ||
30 | #endif | ||
31 | NULL | ||
32 | }; | ||
33 | |||
34 | static struct inode_operations devpts_file_inode_operations = { | ||
35 | #ifdef CONFIG_DEVPTS_FS_XATTR | ||
36 | .setxattr = generic_setxattr, | ||
37 | .getxattr = generic_getxattr, | ||
38 | .listxattr = generic_listxattr, | ||
39 | .removexattr = generic_removexattr, | ||
40 | #endif | ||
41 | }; | ||
42 | |||
43 | static struct vfsmount *devpts_mnt; | ||
44 | static struct dentry *devpts_root; | ||
45 | |||
46 | static struct { | ||
47 | int setuid; | ||
48 | int setgid; | ||
49 | uid_t uid; | ||
50 | gid_t gid; | ||
51 | umode_t mode; | ||
52 | } config = {.mode = 0600}; | ||
53 | |||
54 | static int devpts_remount(struct super_block *sb, int *flags, char *data) | ||
55 | { | ||
56 | int setuid = 0; | ||
57 | int setgid = 0; | ||
58 | uid_t uid = 0; | ||
59 | gid_t gid = 0; | ||
60 | umode_t mode = 0600; | ||
61 | char *this_char; | ||
62 | |||
63 | this_char = NULL; | ||
64 | while ((this_char = strsep(&data, ",")) != NULL) { | ||
65 | int n; | ||
66 | char dummy; | ||
67 | if (!*this_char) | ||
68 | continue; | ||
69 | if (sscanf(this_char, "uid=%i%c", &n, &dummy) == 1) { | ||
70 | setuid = 1; | ||
71 | uid = n; | ||
72 | } else if (sscanf(this_char, "gid=%i%c", &n, &dummy) == 1) { | ||
73 | setgid = 1; | ||
74 | gid = n; | ||
75 | } else if (sscanf(this_char, "mode=%o%c", &n, &dummy) == 1) | ||
76 | mode = n & ~S_IFMT; | ||
77 | else { | ||
78 | printk("devpts: called with bogus options\n"); | ||
79 | return -EINVAL; | ||
80 | } | ||
81 | } | ||
82 | config.setuid = setuid; | ||
83 | config.setgid = setgid; | ||
84 | config.uid = uid; | ||
85 | config.gid = gid; | ||
86 | config.mode = mode; | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | static struct super_operations devpts_sops = { | ||
92 | .statfs = simple_statfs, | ||
93 | .remount_fs = devpts_remount, | ||
94 | }; | ||
95 | |||
96 | static int | ||
97 | devpts_fill_super(struct super_block *s, void *data, int silent) | ||
98 | { | ||
99 | struct inode * inode; | ||
100 | |||
101 | s->s_blocksize = 1024; | ||
102 | s->s_blocksize_bits = 10; | ||
103 | s->s_magic = DEVPTS_SUPER_MAGIC; | ||
104 | s->s_op = &devpts_sops; | ||
105 | s->s_xattr = devpts_xattr_handlers; | ||
106 | s->s_time_gran = 1; | ||
107 | |||
108 | inode = new_inode(s); | ||
109 | if (!inode) | ||
110 | goto fail; | ||
111 | inode->i_ino = 1; | ||
112 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | ||
113 | inode->i_blocks = 0; | ||
114 | inode->i_blksize = 1024; | ||
115 | inode->i_uid = inode->i_gid = 0; | ||
116 | inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR; | ||
117 | inode->i_op = &simple_dir_inode_operations; | ||
118 | inode->i_fop = &simple_dir_operations; | ||
119 | inode->i_nlink = 2; | ||
120 | |||
121 | devpts_root = s->s_root = d_alloc_root(inode); | ||
122 | if (s->s_root) | ||
123 | return 0; | ||
124 | |||
125 | printk("devpts: get root dentry failed\n"); | ||
126 | iput(inode); | ||
127 | fail: | ||
128 | return -ENOMEM; | ||
129 | } | ||
130 | |||
131 | static struct super_block *devpts_get_sb(struct file_system_type *fs_type, | ||
132 | int flags, const char *dev_name, void *data) | ||
133 | { | ||
134 | return get_sb_single(fs_type, flags, data, devpts_fill_super); | ||
135 | } | ||
136 | |||
137 | static struct file_system_type devpts_fs_type = { | ||
138 | .owner = THIS_MODULE, | ||
139 | .name = "devpts", | ||
140 | .get_sb = devpts_get_sb, | ||
141 | .kill_sb = kill_anon_super, | ||
142 | }; | ||
143 | |||
144 | /* | ||
145 | * The normal naming convention is simply /dev/pts/<number>; this conforms | ||
146 | * to the System V naming convention | ||
147 | */ | ||
148 | |||
149 | static struct dentry *get_node(int num) | ||
150 | { | ||
151 | char s[12]; | ||
152 | struct dentry *root = devpts_root; | ||
153 | down(&root->d_inode->i_sem); | ||
154 | return lookup_one_len(s, root, sprintf(s, "%d", num)); | ||
155 | } | ||
156 | |||
157 | int devpts_pty_new(struct tty_struct *tty) | ||
158 | { | ||
159 | int number = tty->index; | ||
160 | struct tty_driver *driver = tty->driver; | ||
161 | dev_t device = MKDEV(driver->major, driver->minor_start+number); | ||
162 | struct dentry *dentry; | ||
163 | struct inode *inode = new_inode(devpts_mnt->mnt_sb); | ||
164 | |||
165 | /* We're supposed to be given the slave end of a pty */ | ||
166 | BUG_ON(driver->type != TTY_DRIVER_TYPE_PTY); | ||
167 | BUG_ON(driver->subtype != PTY_TYPE_SLAVE); | ||
168 | |||
169 | if (!inode) | ||
170 | return -ENOMEM; | ||
171 | |||
172 | inode->i_ino = number+2; | ||
173 | inode->i_blksize = 1024; | ||
174 | inode->i_uid = config.setuid ? config.uid : current->fsuid; | ||
175 | inode->i_gid = config.setgid ? config.gid : current->fsgid; | ||
176 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | ||
177 | init_special_inode(inode, S_IFCHR|config.mode, device); | ||
178 | inode->i_op = &devpts_file_inode_operations; | ||
179 | inode->u.generic_ip = tty; | ||
180 | |||
181 | dentry = get_node(number); | ||
182 | if (!IS_ERR(dentry) && !dentry->d_inode) | ||
183 | d_instantiate(dentry, inode); | ||
184 | |||
185 | up(&devpts_root->d_inode->i_sem); | ||
186 | |||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | struct tty_struct *devpts_get_tty(int number) | ||
191 | { | ||
192 | struct dentry *dentry = get_node(number); | ||
193 | struct tty_struct *tty; | ||
194 | |||
195 | tty = NULL; | ||
196 | if (!IS_ERR(dentry)) { | ||
197 | if (dentry->d_inode) | ||
198 | tty = dentry->d_inode->u.generic_ip; | ||
199 | dput(dentry); | ||
200 | } | ||
201 | |||
202 | up(&devpts_root->d_inode->i_sem); | ||
203 | |||
204 | return tty; | ||
205 | } | ||
206 | |||
207 | void devpts_pty_kill(int number) | ||
208 | { | ||
209 | struct dentry *dentry = get_node(number); | ||
210 | |||
211 | if (!IS_ERR(dentry)) { | ||
212 | struct inode *inode = dentry->d_inode; | ||
213 | if (inode) { | ||
214 | inode->i_nlink--; | ||
215 | d_delete(dentry); | ||
216 | dput(dentry); | ||
217 | } | ||
218 | dput(dentry); | ||
219 | } | ||
220 | up(&devpts_root->d_inode->i_sem); | ||
221 | } | ||
222 | |||
223 | static int __init init_devpts_fs(void) | ||
224 | { | ||
225 | int err = register_filesystem(&devpts_fs_type); | ||
226 | if (!err) { | ||
227 | devpts_mnt = kern_mount(&devpts_fs_type); | ||
228 | if (IS_ERR(devpts_mnt)) | ||
229 | err = PTR_ERR(devpts_mnt); | ||
230 | } | ||
231 | return err; | ||
232 | } | ||
233 | |||
234 | static void __exit exit_devpts_fs(void) | ||
235 | { | ||
236 | unregister_filesystem(&devpts_fs_type); | ||
237 | mntput(devpts_mnt); | ||
238 | } | ||
239 | |||
240 | module_init(init_devpts_fs) | ||
241 | module_exit(exit_devpts_fs) | ||
242 | MODULE_LICENSE("GPL"); | ||
diff --git a/fs/devpts/xattr_security.c b/fs/devpts/xattr_security.c new file mode 100644 index 000000000000..864cb5c79baa --- /dev/null +++ b/fs/devpts/xattr_security.c | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * Security xattr support for devpts. | ||
3 | * | ||
4 | * Author: Stephen Smalley <sds@epoch.ncsc.mil> | ||
5 | * Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms of the GNU General Public License as published by the Free | ||
9 | * Software Foundation; either version 2 of the License, or (at your option) | ||
10 | * any later version. | ||
11 | */ | ||
12 | #include <linux/string.h> | ||
13 | #include <linux/fs.h> | ||
14 | #include <linux/security.h> | ||
15 | #include <linux/xattr.h> | ||
16 | |||
17 | static size_t | ||
18 | devpts_xattr_security_list(struct inode *inode, char *list, size_t list_len, | ||
19 | const char *name, size_t name_len) | ||
20 | { | ||
21 | return security_inode_listsecurity(inode, list, list_len); | ||
22 | } | ||
23 | |||
24 | static int | ||
25 | devpts_xattr_security_get(struct inode *inode, const char *name, | ||
26 | void *buffer, size_t size) | ||
27 | { | ||
28 | if (strcmp(name, "") == 0) | ||
29 | return -EINVAL; | ||
30 | return security_inode_getsecurity(inode, name, buffer, size); | ||
31 | } | ||
32 | |||
33 | static int | ||
34 | devpts_xattr_security_set(struct inode *inode, const char *name, | ||
35 | const void *value, size_t size, int flags) | ||
36 | { | ||
37 | if (strcmp(name, "") == 0) | ||
38 | return -EINVAL; | ||
39 | return security_inode_setsecurity(inode, name, value, size, flags); | ||
40 | } | ||
41 | |||
42 | struct xattr_handler devpts_xattr_security_handler = { | ||
43 | .prefix = XATTR_SECURITY_PREFIX, | ||
44 | .list = devpts_xattr_security_list, | ||
45 | .get = devpts_xattr_security_get, | ||
46 | .set = devpts_xattr_security_set, | ||
47 | }; | ||