aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/xattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs/xattr.c')
-rw-r--r--fs/reiserfs/xattr.c128
1 files changed, 30 insertions, 98 deletions
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index cc061bfd437b..ffb79c48c5bf 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -368,15 +368,13 @@ static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
368 if (d_reclen <= 32) { 368 if (d_reclen <= 32) {
369 local_buf = small_buf; 369 local_buf = small_buf;
370 } else { 370 } else {
371 local_buf = 371 local_buf = kmalloc(d_reclen, GFP_NOFS);
372 reiserfs_kmalloc(d_reclen, GFP_NOFS, inode->i_sb);
373 if (!local_buf) { 372 if (!local_buf) {
374 pathrelse(&path_to_entry); 373 pathrelse(&path_to_entry);
375 return -ENOMEM; 374 return -ENOMEM;
376 } 375 }
377 if (item_moved(&tmp_ih, &path_to_entry)) { 376 if (item_moved(&tmp_ih, &path_to_entry)) {
378 reiserfs_kfree(local_buf, d_reclen, 377 kfree(local_buf);
379 inode->i_sb);
380 378
381 /* sigh, must retry. Do this same offset again */ 379 /* sigh, must retry. Do this same offset again */
382 next_pos = d_off; 380 next_pos = d_off;
@@ -399,13 +397,12 @@ static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
399 if (filldir(dirent, local_buf, d_reclen, d_off, d_ino, 397 if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
400 DT_UNKNOWN) < 0) { 398 DT_UNKNOWN) < 0) {
401 if (local_buf != small_buf) { 399 if (local_buf != small_buf) {
402 reiserfs_kfree(local_buf, d_reclen, 400 kfree(local_buf);
403 inode->i_sb);
404 } 401 }
405 goto end; 402 goto end;
406 } 403 }
407 if (local_buf != small_buf) { 404 if (local_buf != small_buf) {
408 reiserfs_kfree(local_buf, d_reclen, inode->i_sb); 405 kfree(local_buf);
409 } 406 }
410 } /* while */ 407 } /* while */
411 408
@@ -1322,109 +1319,44 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1322 return err; 1319 return err;
1323} 1320}
1324 1321
1325static int 1322static int reiserfs_check_acl(struct inode *inode, int mask)
1326__reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd,
1327 int need_lock)
1328{ 1323{
1329 umode_t mode = inode->i_mode; 1324 struct posix_acl *acl;
1330 1325 int error = -EAGAIN; /* do regular unix permission checks by default */
1331 if (mask & MAY_WRITE) {
1332 /*
1333 * Nobody gets write access to a read-only fs.
1334 */
1335 if (IS_RDONLY(inode) &&
1336 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
1337 return -EROFS;
1338 1326
1339 /* 1327 reiserfs_read_lock_xattr_i(inode);
1340 * Nobody gets write access to an immutable file. 1328 reiserfs_read_lock_xattrs(inode->i_sb);
1341 */
1342 if (IS_IMMUTABLE(inode))
1343 return -EACCES;
1344 }
1345 1329
1346 /* We don't do permission checks on the internal objects. 1330 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
1347 * Permissions are determined by the "owning" object. */
1348 if (is_reiserfs_priv_object(inode))
1349 return 0;
1350 1331
1351 if (current->fsuid == inode->i_uid) { 1332 reiserfs_read_unlock_xattrs(inode->i_sb);
1352 mode >>= 6; 1333 reiserfs_read_unlock_xattr_i(inode);
1353#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1354 } else if (reiserfs_posixacl(inode->i_sb) &&
1355 get_inode_sd_version(inode) != STAT_DATA_V1) {
1356 struct posix_acl *acl;
1357
1358 /* ACL can't contain additional permissions if
1359 the ACL_MASK entry is 0 */
1360 if (!(mode & S_IRWXG))
1361 goto check_groups;
1362
1363 if (need_lock) {
1364 reiserfs_read_lock_xattr_i(inode);
1365 reiserfs_read_lock_xattrs(inode->i_sb);
1366 }
1367 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
1368 if (need_lock) {
1369 reiserfs_read_unlock_xattrs(inode->i_sb);
1370 reiserfs_read_unlock_xattr_i(inode);
1371 }
1372 if (IS_ERR(acl)) {
1373 if (PTR_ERR(acl) == -ENODATA)
1374 goto check_groups;
1375 return PTR_ERR(acl);
1376 }
1377 1334
1378 if (acl) { 1335 if (acl) {
1379 int err = posix_acl_permission(inode, acl, mask); 1336 if (!IS_ERR(acl)) {
1337 error = posix_acl_permission(inode, acl, mask);
1380 posix_acl_release(acl); 1338 posix_acl_release(acl);
1381 if (err == -EACCES) { 1339 } else if (PTR_ERR(acl) != -ENODATA)
1382 goto check_capabilities; 1340 error = PTR_ERR(acl);
1383 }
1384 return err;
1385 } else {
1386 goto check_groups;
1387 }
1388#endif
1389 } else {
1390 check_groups:
1391 if (in_group_p(inode->i_gid))
1392 mode >>= 3;
1393 } 1341 }
1394 1342
1395 /* 1343 return error;
1396 * If the DACs are ok we don't need any capability check. 1344}
1397 */
1398 if (((mode & mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == mask))
1399 return 0;
1400 1345
1401 check_capabilities: 1346int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd)
1347{
1402 /* 1348 /*
1403 * Read/write DACs are always overridable. 1349 * We don't do permission checks on the internal objects.
1404 * Executable DACs are overridable if at least one exec bit is set. 1350 * Permissions are determined by the "owning" object.
1405 */ 1351 */
1406 if (!(mask & MAY_EXEC) || 1352 if (is_reiserfs_priv_object(inode))
1407 (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode)) 1353 return 0;
1408 if (capable(CAP_DAC_OVERRIDE))
1409 return 0;
1410 1354
1411 /* 1355 /*
1412 * Searching includes executable on directories, else just read. 1356 * Stat data v1 doesn't support ACLs.
1413 */ 1357 */
1414 if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE))) 1358 if (get_inode_sd_version(inode) == STAT_DATA_V1)
1415 if (capable(CAP_DAC_READ_SEARCH)) 1359 return generic_permission(inode, mask, NULL);
1416 return 0; 1360 else
1417 1361 return generic_permission(inode, mask, reiserfs_check_acl);
1418 return -EACCES;
1419}
1420
1421int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd)
1422{
1423 return __reiserfs_permission(inode, mask, nd, 1);
1424}
1425
1426int
1427reiserfs_permission_locked(struct inode *inode, int mask, struct nameidata *nd)
1428{
1429 return __reiserfs_permission(inode, mask, nd, 0);
1430} 1362}