Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-trusted_ea-2.4.20.patch
1  fs/ext3/xattr.c            |   12 +++++-
2  fs/ext3/xattr_trusted.c    |   86 +++++++++++++++++++++++++++++++++++++++++++++
3  include/linux/ext3_xattr.h |    6 +++
4  3 files changed, 102 insertions(+), 2 deletions(-)
5
6 Index: linux-2.4.20/fs/ext3/xattr.c
7 ===================================================================
8 --- linux-2.4.20.orig/fs/ext3/xattr.c   2003-10-22 02:29:40.000000000 +0400
9 +++ linux-2.4.20/fs/ext3/xattr.c        2003-10-24 01:03:22.000000000 +0400
10 @@ -1771,18 +1771,25 @@
11  int __init
12  init_ext3_xattr(void)
13  {
14 +       int error;
15 +
16         ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL,
17                 sizeof(struct mb_cache_entry) +
18                 sizeof(struct mb_cache_entry_index), 1, 61);
19         if (!ext3_xattr_cache)
20                 return -ENOMEM;
21  
22 -       return 0;
23 +       error = init_ext3_xattr_trusted();
24 +       if (error)
25 +               mb_cache_destroy(ext3_xattr_cache);
26 +
27 +       return error;
28  }
29  
30  void
31  exit_ext3_xattr(void)
32  {
33 +       exit_ext3_xattr_trusted();
34         if (ext3_xattr_cache)
35                 mb_cache_destroy(ext3_xattr_cache);
36         ext3_xattr_cache = NULL;
37 @@ -1793,12 +1800,13 @@
38  int __init
39  init_ext3_xattr(void)
40  {
41 -       return 0;
42 +       return init_ext3_xattr_trusted();
43  }
44  
45  void
46  exit_ext3_xattr(void)
47  {
48 +       exit_ext3_xattr_trusted();
49  }
50  
51  #endif  /* CONFIG_EXT3_FS_XATTR_SHARING */
52 Index: linux-2.4.20/fs/ext3/xattr_trusted.c
53 ===================================================================
54 --- linux-2.4.20.orig/fs/ext3/xattr_trusted.c   2003-10-24 01:03:22.000000000 +0400
55 +++ linux-2.4.20/fs/ext3/xattr_trusted.c        2003-10-24 01:03:22.000000000 +0400
56 @@ -0,0 +1,86 @@
57 +/*
58 + * linux/fs/ext3/xattr_trusted.c
59 + * Handler for trusted extended attributes.
60 + *
61 + * Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
62 + */
63 +
64 +#include <linux/module.h>
65 +#include <linux/string.h>
66 +#include <linux/fs.h>
67 +#include <linux/ext3_jbd.h>
68 +#include <linux/ext3_fs.h>
69 +#include <linux/ext3_xattr.h>
70 +
71 +#define XATTR_TRUSTED_PREFIX "trusted."
72 +
73 +static size_t
74 +ext3_xattr_trusted_list(char *list, struct inode *inode,
75 +                       const char *name, int name_len)
76 +{
77 +       const int prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
78 +
79 +       if (!capable(CAP_SYS_ADMIN))
80 +               return 0;
81 +
82 +       if (list) {
83 +               memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
84 +               memcpy(list+prefix_len, name, name_len);
85 +               list[prefix_len + name_len] = '\0';
86 +       }
87 +       return prefix_len + name_len + 1;
88 +}
89 +
90 +static int
91 +ext3_xattr_trusted_get(struct inode *inode, const char *name,
92 +                      void *buffer, size_t size)
93 +{
94 +       if (strcmp(name, "") == 0)
95 +               return -EINVAL;
96 +       if (!capable(CAP_SYS_ADMIN))
97 +               return -EPERM;
98 +       return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name,
99 +                             buffer, size);
100 +}
101 +
102 +static int
103 +ext3_xattr_trusted_set(struct inode *inode, const char *name,
104 +                      const void *value, size_t size, int flags)
105 +{
106 +       handle_t *handle;
107 +       int error;
108 +
109 +       if (strcmp(name, "") == 0)
110 +               return -EINVAL;
111 +       if (!capable(CAP_SYS_ADMIN))
112 +               return -EPERM;
113 +       handle = ext3_journal_start(inode, EXT3_XATTR_TRANS_BLOCKS);
114 +       if (IS_ERR(handle))
115 +               return PTR_ERR(handle);
116 +       error = ext3_xattr_set(handle, inode, EXT3_XATTR_INDEX_TRUSTED, name,
117 +                              value, size, flags);
118 +       ext3_journal_stop(handle, inode);
119 +
120 +       return error;
121 +}
122 +
123 +struct ext3_xattr_handler ext3_xattr_trusted_handler = {
124 +       .prefix = XATTR_TRUSTED_PREFIX,
125 +       .list   = ext3_xattr_trusted_list,
126 +       .get    = ext3_xattr_trusted_get,
127 +       .set    = ext3_xattr_trusted_set,
128 +};
129 +
130 +int __init
131 +init_ext3_xattr_trusted(void)
132 +{
133 +       return ext3_xattr_register(EXT3_XATTR_INDEX_TRUSTED,
134 +                                  &ext3_xattr_trusted_handler);
135 +}
136 +
137 +void
138 +exit_ext3_xattr_trusted(void)
139 +{
140 +       ext3_xattr_unregister(EXT3_XATTR_INDEX_TRUSTED,
141 +                             &ext3_xattr_trusted_handler);
142 +}
143 Index: linux-2.4.20/include/linux/ext3_xattr.h
144 ===================================================================
145 --- linux-2.4.20.orig/include/linux/ext3_xattr.h        2003-10-22 02:29:39.000000000 +0400
146 +++ linux-2.4.20/include/linux/ext3_xattr.h     2003-10-24 01:03:22.000000000 +0400
147 @@ -21,6 +21,9 @@
148  #define EXT3_XATTR_INDEX_USER                  1
149  #define EXT3_XATTR_INDEX_POSIX_ACL_ACCESS      2
150  #define EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT     3
151 +#define EXT3_XATTR_INDEX_TRUSTED               4
152 +#define EXT3_XATTR_INDEX_LUSTRE                        5
153 +#define EXT3_XATTR_INDEX_SECURITY              6
154  
155  struct ext3_xattr_header {
156         __u32   h_magic;        /* magic number for identification */
157 @@ -84,6 +87,9 @@
158  extern int init_ext3_xattr(void) __init;
159  extern void exit_ext3_xattr(void);
160  
161 +extern int init_ext3_xattr_trusted(void) __init;
162 +extern void exit_ext3_xattr_trusted(void);
163 +
164  # else  /* CONFIG_EXT3_FS_XATTR */
165  #  define ext3_setxattr                NULL
166  #  define ext3_getxattr                NULL
167 Index: linux-2.4.20/fs/ext3/Makefile
168 ===================================================================
169 --- linux-2.4.20.orig/fs/ext3/Makefile  2003-10-22 02:29:40.000000000 +0400
170 +++ linux-2.4.20/fs/ext3/Makefile       2003-10-24 01:03:47.000000000 +0400
171 @@ -12,7 +12,8 @@
172  export-objs := ext3-exports.o
173  
174  obj-y    := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o iopen.o \
175 -               ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o
176 +               ioctl.o namei.o super.o symlink.o hash.o ext3-exports.o \
177 +               xattr_trusted.o
178  obj-m    := $(O_TARGET)
179  
180  export-objs += xattr.o