Commit | Line | Data |
---|---|---|
652ecc20 KK |
1 | /* |
2 | * JFFS2 -- Journalling Flash File System, Version 2. | |
aa98d7cf | 3 | * |
c00c310e | 4 | * Copyright © 2006 NEC Corporation |
aa98d7cf | 5 | * |
652ecc20 KK |
6 | * Created by KaiGai Kohei <kaigai@ak.jp.nec.com> |
7 | * | |
8 | * For licensing information, see the file 'LICENCE' in this directory. | |
9 | * | |
10 | */ | |
c00c310e | 11 | |
aa98d7cf KK |
12 | #include <linux/kernel.h> |
13 | #include <linux/slab.h> | |
14 | #include <linux/fs.h> | |
15 | #include <linux/time.h> | |
16 | #include <linux/pagemap.h> | |
17 | #include <linux/highmem.h> | |
18 | #include <linux/crc32.h> | |
19 | #include <linux/jffs2.h> | |
20 | #include <linux/xattr.h> | |
21 | #include <linux/mtd/mtd.h> | |
22 | #include <linux/security.h> | |
23 | #include "nodelist.h" | |
24 | ||
9d8f13ba | 25 | /* ---- Initial Security Label(s) Attachment callback --- */ |
273a65ad NP |
26 | static int jffs2_initxattrs(struct inode *inode, |
27 | const struct xattr *xattr_array, void *fs_info) | |
aa98d7cf | 28 | { |
9d8f13ba MZ |
29 | const struct xattr *xattr; |
30 | int err = 0; | |
aa98d7cf | 31 | |
9d8f13ba MZ |
32 | for (xattr = xattr_array; xattr->name != NULL; xattr++) { |
33 | err = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, | |
34 | xattr->name, xattr->value, | |
35 | xattr->value_len, 0); | |
36 | if (err < 0) | |
37 | break; | |
aa98d7cf | 38 | } |
9d8f13ba MZ |
39 | return err; |
40 | } | |
aa98d7cf | 41 | |
9d8f13ba MZ |
42 | /* ---- Initial Security Label(s) Attachment ----------- */ |
43 | int jffs2_init_security(struct inode *inode, struct inode *dir, | |
44 | const struct qstr *qstr) | |
45 | { | |
46 | return security_inode_init_security(inode, dir, qstr, | |
47 | &jffs2_initxattrs, NULL); | |
aa98d7cf KK |
48 | } |
49 | ||
50 | /* ---- XATTR Handler for "security.*" ----------------- */ | |
431547b3 CH |
51 | static int jffs2_security_getxattr(struct dentry *dentry, const char *name, |
52 | void *buffer, size_t size, int type) | |
aa98d7cf KK |
53 | { |
54 | if (!strcmp(name, "")) | |
55 | return -EINVAL; | |
56 | ||
431547b3 CH |
57 | return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, |
58 | name, buffer, size); | |
aa98d7cf KK |
59 | } |
60 | ||
431547b3 CH |
61 | static int jffs2_security_setxattr(struct dentry *dentry, const char *name, |
62 | const void *buffer, size_t size, int flags, int type) | |
aa98d7cf KK |
63 | { |
64 | if (!strcmp(name, "")) | |
65 | return -EINVAL; | |
66 | ||
431547b3 CH |
67 | return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, |
68 | name, buffer, size, flags); | |
aa98d7cf KK |
69 | } |
70 | ||
431547b3 CH |
71 | static size_t jffs2_security_listxattr(struct dentry *dentry, char *list, |
72 | size_t list_size, const char *name, size_t name_len, int type) | |
aa98d7cf KK |
73 | { |
74 | size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1; | |
75 | ||
76 | if (list && retlen <= list_size) { | |
77 | strcpy(list, XATTR_SECURITY_PREFIX); | |
78 | strcpy(list + XATTR_SECURITY_PREFIX_LEN, name); | |
79 | } | |
80 | ||
81 | return retlen; | |
82 | } | |
83 | ||
365f0cb9 | 84 | const struct xattr_handler jffs2_security_xattr_handler = { |
aa98d7cf KK |
85 | .prefix = XATTR_SECURITY_PREFIX, |
86 | .list = jffs2_security_listxattr, | |
87 | .set = jffs2_security_setxattr, | |
88 | .get = jffs2_security_getxattr | |
89 | }; |