1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
|
--- linux/fs/Config.in Thu Jan 3 14:16:35 2002
+++ linux/fs/Config.in Thu Jan 3 14:17:07 2002
@@ -6,7 +6,9 @@
bool 'Quota support' CONFIG_QUOTA
tristate 'Kernel automounter support' CONFIG_AUTOFS_FS
-
+if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
+ bool ' Linux trustees (ACL) support (EXPERIMENTAL)' CONFIG_TRUSTEES
+fi
if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
tristate 'ADFS filesystem support (read only) (EXPERIMENTAL)' CONFIG_ADFS_FS
--- linux/include/linux/fs.h Thu Jan 3 14:16:35 2002
+++ linux/include/linux/fs.h Thu Jan 3 14:22:11 2002
@@ -551,7 +551,7 @@
short int s_ibasket_count;
short int s_ibasket_max;
struct list_head s_dirty; /* dirty inodes */
-
+ struct vfsmount * mnt;
union {
struct minix_sb_info minix_sb;
struct ext2_sb_info ext2_sb;
@@ -839,6 +839,11 @@
extern int notify_change(struct dentry *, struct iattr *);
extern int vfs_permission(struct inode * inode,int mask);
extern int permission(struct inode * inode,int mask);
+#ifdef CONFIG_TRUSTEES
+extern int permission_dentry(struct dentry * dentry,int mask);
+#else
+#define permission_dentry(DENTRY,MASK) permission(DENTRY->d_inode,MASK)
+#endif
extern int get_write_access(struct inode *inode);
extern void put_write_access(struct inode *inode);
extern struct dentry * open_namei(const char * pathname, int flag, int mode);
--- linux/fs/namei.c Thu Jan 3 14:16:35 2002
+++ linux/fs/namei.c Thu Jan 3 14:17:07 2002
@@ -10,6 +10,7 @@
/* [Feb 1997 T. Schoebel-Theuer] Complete rewrite of the pathname
* lookup logic.
+ * Linux Trustees support added (c) 1999-2000 Vyacheslav Zavadsky
*/
#include <linux/mm.h>
@@ -24,7 +25,9 @@
#include <asm/pgtable.h>
#include <asm/namei.h>
-
+#ifdef CONFIG_TRUSTEES
+#include <linux/trustee.h>
+#endif
/* This can be removed after the beta phase. */
#define CACHE_SUPERVISE /* debug the correctness of dcache entries */
#undef DEBUG /* some other debugging */
@@ -365,7 +368,7 @@
unsigned int flags;
unsigned int c;
- err = permission(inode, MAY_EXEC);
+ err = permission_dentry(base, MAY_EXEC);
dentry = ERR_PTR(err);
if (err)
break;
@@ -531,7 +534,7 @@
int error;
if (!victim->d_inode || victim->d_parent->d_inode != dir)
return -ENOENT;
- error = permission(dir,MAY_WRITE | MAY_EXEC);
+ error = permission_dentry(victim->d_parent,MAY_WRITE | MAY_EXEC);
if (error)
return error;
if (IS_APPEND(dir))
@@ -562,7 +565,7 @@
static inline int may_create(struct inode *dir, struct dentry *child) {
if (child->d_inode)
return -EEXIST;
- return permission(dir,MAY_WRITE | MAY_EXEC);
+ return permission_dentry(child->d_parent,MAY_WRITE | MAY_EXEC);
}
static inline struct dentry *get_parent(struct dentry *dentry)
@@ -756,7 +759,7 @@
if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE))
goto exit;
- error = permission(inode,acc_mode);
+ error = permission_dentry(dentry,acc_mode);
if (error)
goto exit;
@@ -1274,7 +1277,7 @@
* we'll need to flip '..'.
*/
if (new_dir != old_dir) {
- error = permission(old_dentry->d_inode, MAY_WRITE);
+ error = permission_dentry(old_dentry, MAY_WRITE);
}
if (error)
return error;
@@ -1413,3 +1416,102 @@
unlock_kernel();
return error;
}
+
+
+/* Begin Trustees code */
+ #ifdef CONFIG_TRUSTEES
+ static int inline trustee_mask_to_normal_mask(int mask, int isdir) {
+ int r=0;
+ if ((mask & TRUSTEE_READ_MASK) && !isdir) r |= S_IROTH;
+ if ((mask & TRUSTEE_READ_DIR_MASK) && isdir) r |= S_IROTH;
+ if (mask & TRUSTEE_WRITE_MASK) r |= S_IWOTH;
+ if ((mask & TRUSTEE_BROWSE_MASK) && isdir) r |= S_IXOTH;
+ if ((mask & TRUSTEE_EXECUTE_MASK) && !isdir) r |= S_IXOTH;
+ return r;
+ }
+ int permission_dentry(struct dentry * dentry,int mask)
+ {
+ int p=permission(dentry->d_inode,mask);
+ int trusteemask,isdir;
+ int mode = dentry->d_inode->i_mode;
+ struct inode * inode=dentry->d_inode;
+ int res= -EACCES;
+
+ #ifdef TRUSTEE_DEBUG
+ if (current->fsuid != TRUSTEE_DEBUG_USER) { return p; }
+ #endif
+
+ if ((mask & S_IWOTH) && IS_RDONLY(inode) &&
+ (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
+ { res= -EROFS; /* Nobody gets write access to a read-only fs */
+ goto out;
+ }
+ else if ((mask & S_IWOTH) && IS_IMMUTABLE(inode))
+ {res= -EACCES; /* Nobody gets write access to an immutable file */
+ goto out;
+ }
+ isdir=S_ISDIR(mode);
+ trusteemask=get_trustee_mask_for_dentry(dentry,current->fsuid);
+ #ifdef TRUSTEE_DEBUG
+ printk("dentry_permission is called , trusteemask is %x, unix permission is %d, mask is %x, mode is %x\n", trusteemask,p,mask,mode);
+ #endif
+ /* grant superuser priveleges */
+ if ( capable(CAP_DAC_OVERRIDE))
+ {
+ #ifdef TRUSTEE_DEBUG
+ printk("Superuser write permission granted");
+ #endif
+ res=0;
+ goto out;
+ }
+ if ((mask == S_IROTH) ||
+ (S_ISDIR(mode) && !(mask & ~(S_IROTH | S_IXOTH))))
+ if (capable(CAP_DAC_READ_SEARCH))
+ {
+ #ifdef TRUSTEE_DEBUG
+ printk("Superuser read permission granted");
+ #endif
+ res=0;
+ goto out;
+ }
+ if (trustee_mask_to_normal_mask(trusteemask >> TRUSTEE_NUM_ACL_BITS,isdir) & mask & S_IRWXO) {
+ #ifdef TRUSTEE_DEBUG
+ printk(" trustee access denied ");
+ #endif
+ return -EACCES;} /* no permission if denied */
+ if ((!((trusteemask >> TRUSTEE_NUM_ACL_BITS) & TRUSTEE_USE_UNIX_MASK)) && (trusteemask & TRUSTEE_USE_UNIX_MASK) && (!p)) {
+ #ifdef TRUSTEE_DEBUG
+ printk("unix access granted");
+ #endif
+ res=0;
+ goto out;
+ } /* grant ordinary unix permission */
+ if (!(mode & S_IXOTH) && !((mode >> 3) & S_IXOTH) && !((mode >> 6) & S_IXOTH) && (!isdir) && (mask & S_IXOTH)) return -EACCES; /* execute permission for non-executable file can not be granted */
+ if (((trustee_mask_to_normal_mask(trusteemask,isdir) & mask & S_IRWXO) == mask))
+ {
+ #ifdef TRUSTEE_DEBUG
+ printk("trustee permission granted");
+ #endif
+ res= 0;
+ goto out;
+ }
+
+ out:
+
+ return res;
+ }
+ #else /* dummy code for sys_set_trustee */
+ asmlinkage int sys_set_trustee(const char * name, struct trustee_permission * permission,int command) {
+ return -ENOSYS;
+ }
+ #endif
+
+ /* end trustees code */
+
+
+
+
+
+
+
+
--- linux/fs/open.c Thu Jan 3 14:16:35 2002
+++ linux/fs/open.c Thu Jan 3 14:18:22 2002
@@ -2,6 +2,7 @@
* linux/fs/open.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
+ * Linux Trustees support added (c) 1999 Vyacheslav Zavadsky
*/
#include <linux/mm.h>
@@ -105,7 +106,7 @@
if (S_ISDIR(inode->i_mode))
goto dput_and_out;
- error = permission(inode,MAY_WRITE);
+ error = permission_dentry(dentry,MAY_WRITE);
if (error)
goto dput_and_out;
@@ -215,7 +216,7 @@
newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
} else {
if (current->fsuid != inode->i_uid &&
- (error = permission(inode,MAY_WRITE)) != 0)
+ (error = permission_dentry(dentry,MAY_WRITE)) != 0)
goto dput_and_out;
}
error = notify_change(dentry, &newattrs);
@@ -262,7 +263,7 @@
newattrs.ia_mtime = times[1].tv_sec;
newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
} else {
- if ((error = permission(inode,MAY_WRITE)) != 0)
+ if ((error = permission_dentry(dentry,MAY_WRITE)) != 0)
goto dput_and_out;
}
error = notify_change(dentry, &newattrs);
@@ -278,12 +279,19 @@
* We do this by temporarily clearing all FS-related capabilities and
* switching the fsuid/fsgid around to the real ones.
*/
-asmlinkage int sys_access(const char * filename, int mode)
+
+asmlinkage int sys_access_uid(const char * filename, int mode,uid_t uid,gid_t gid)
{
struct dentry * dentry;
int old_fsuid, old_fsgid;
kernel_cap_t old_cap;
+ int group_ok=0;
int res = -EINVAL;
+ group_ok=capable(CAP_DAC_READ_SEARCH) || in_group_p(gid);
+ if (capable(CAP_DAC_READ_SEARCH)) goto can_do;
+ if ((uid==current->uid) || (uid==current->fsuid)) goto can_do;
+ return res;
+ can_do:
lock_kernel();
if (mode != (mode & S_IRWXO)) /* where's F_OK, X_OK, W_OK, R_OK? */
@@ -292,11 +300,12 @@
old_fsgid = current->fsgid;
old_cap = current->cap_effective;
- current->fsuid = current->uid;
- current->fsgid = current->gid;
+ current->fsuid = uid;
+ if ((gid!=current->gid) && !capable(CAP_DAC_READ_SEARCH) && !in_group_p(gid) && !group_ok) goto out;
+ current->fsgid = gid;
/* Clear the capabilities if we switch to a non-root user */
- if (current->uid)
+ if (uid)
cap_clear(current->cap_effective);
else
current->cap_effective = current->cap_permitted;
@@ -304,7 +313,7 @@
dentry = namei(filename);
res = PTR_ERR(dentry);
if (!IS_ERR(dentry)) {
- res = permission(dentry->d_inode, mode);
+ res = permission_dentry(dentry, mode);
/* SUSv2 says to return EROFS for open() and access()
for files on a read-only filesystem, when writing
@@ -325,6 +334,11 @@
return res;
}
+asmlinkage int sys_access(const char * filename, int mode) {
+ return sys_access_uid(filename,mode,current->uid,current->gid);
+}
+
+
asmlinkage int sys_chdir(const char * filename)
{
int error;
@@ -344,7 +358,7 @@
if (!S_ISDIR(inode->i_mode))
goto dput_and_out;
- error = permission(inode,MAY_EXEC);
+ error = permission_dentry(dentry,MAY_EXEC);
if (error)
goto dput_and_out;
@@ -384,7 +398,7 @@
if (!S_ISDIR(inode->i_mode))
goto out_putf;
- error = permission(inode, MAY_EXEC);
+ error = permission_dentry(dentry, MAY_EXEC);
if (!error) {
struct dentry *tmp = current->fs->pwd;
current->fs->pwd = dget(dentry);
@@ -416,7 +430,7 @@
if (!S_ISDIR(inode->i_mode))
goto dput_and_out;
- error = permission(inode,MAY_EXEC);
+ error = permission_dentry(dentry,MAY_EXEC);
if (error)
goto dput_and_out;
--- linux/include/linux/trustee.h Thu Jan 3 14:16:35 2002
+++ linux/include/linux/trustee.h Thu Jan 3 14:23:57 2002
@@ -0,0 +1,73 @@
+/*
+ * (c) 1999-2000 Vyacheslav Zavadsky
+ * GPLed
+ */
+
+#ifndef _LINUX_TRUSTEE_H
+#define _LINUX_TRUSTEE_H
+#include <linux/config.h>
+#include <linux/types.h>
+#include <linux/dcache.h>
+#include <linux/trustee_struct.h>
+#include <linux/kdev_t.h>
+#include <linux/init.h>
+
+
+
+
+
+
+
+/* this function evaluates the trustee mask applicable to given name for given user. it is does not checks the trustees for parent and higher levels
+
+result & TRUSTEE_ACL_MASK - allow mask
+(result >> TRUSTEE_NUM_ACL_BITS) & TRUSTEE_ACL_MASK - deny mask
+old_mask - the same mask for higher level
+*/
+#define TRUSTEE_DEFAULT_MASK TRUSTEE_USE_UNIX_MASK
+
+
+struct trustee_name {
+ kdev_t dev;
+ char * filename;
+ char * devname; /* ONLY if MAJOR(dev)==0 */
+
+
+
+};
+
+
+extern int get_trustee_mask_for_name(const struct trustee_name * name,uid_t user,int oldmask,int height);
+
+extern int get_trustee_mask_for_dentry(struct dentry * dentry,uid_t user);
+
+#define TRUSTEE_INITIAL_HASH_SIZE 4
+#define TRUSTEE_INITIAL_NAME_BUFFER 256
+
+
+/* name & permission are ignored if command=TRUSTEE_COMMAND_REMOVE_ALL */
+/* permission is ignored if command=TRUSTEE_COMMAND_REMOVE */
+
+
+
+extern int sys_set_trustee(const struct trustee_command * c);
+
+/*#define TRUSTEE_DEBUG 1*/
+#define TRUSTEE_DEBUG_USER 500
+extern __initfunc(void proc_trustee_init(void));
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- linux/fs/trustee.c Thu Jan 3 14:16:35 2002
+++ linux/fs/trustee.c Thu Jan 3 14:17:07 2002
@@ -0,0 +1,474 @@
+/*
+ * (c) 1999-2000 Vyacheslav Zavadsky
+ */
+
+#include <linux/fs.h>
+#include <linux/dcache.h>
+#include <linux/trustee.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/malloc.h>
+#include <linux/slab.h>
+#include <linux/smp_lock.h>
+#include <linux/poll.h>
+#include <linux/sched.h>
+#include <linux/limits.h>
+typedef struct permission_capsule * Ppermission_capsule;
+struct permission_capsule {
+ Ppermission_capsule next;
+ struct trustee_permission permission;
+};
+
+
+struct trustee_hash_element {
+ int usage; /* 0 -unused, 1- deleted, 2 - used */
+ struct trustee_name name;
+ Ppermission_capsule list;
+
+};
+static struct trustee_hash_element * trustee_hash=NULL;
+static int trustee_hash_size=0, trustee_hash_used=0, trustee_hash_deleted=0;
+
+
+static inline void free_hash_element_list(struct trustee_hash_element e) {
+ struct permission_capsule * l1, *l2;
+ l1=e.list;
+ while (l1!=NULL) {
+ l2=l1;
+ l1=(struct permission_capsule *)l1->next;
+ kfree(l2);
+ }
+ e.list=NULL;
+
+}
+
+
+static inline void free_trustee_name(struct trustee_name * name) {
+ kfree(name->filename);
+ if (TRUSTEE_HASDEVNAME(*name)) {
+ kfree(name->devname);
+ }
+
+}
+
+
+
+static inline void free_hash_element(struct trustee_hash_element e) {
+ e.usage=1;
+ free_hash_element_list(e);
+ free_trustee_name(&e.name);
+
+
+}
+
+static inline unsigned int hash_string(const char * s) {
+ unsigned int v=1;
+ while (*s) {
+
+ v = (v << 2) | (v >> (4*sizeof(v)-2));
+ v = (v+(*s))^(*s);
+ s++;
+ }
+ return v;
+
+}
+
+static inline unsigned int hash(const struct trustee_name * name ) {
+ unsigned int v=hash_string(name->filename);
+ if (TRUSTEE_HASDEVNAME(*name)) {
+ v^=hash_string(name->devname);
+ } else {
+ v^=name->dev;
+ }
+
+ return v;
+}
+
+static inline int trustee_name_cmp(const struct trustee_name * n1, const struct trustee_name * n2) {
+ if (TRUSTEE_HASDEVNAME(*n1) && TRUSTEE_HASDEVNAME(*n2))
+ return (strcmp(n1->devname,n2->devname)==0) && (strcmp(n1->filename,n2->filename)==0);
+ else if ((!TRUSTEE_HASDEVNAME(*n1)) && (!TRUSTEE_HASDEVNAME(*n2)))
+ return ((n1->dev==n2->dev) && (strcmp(n1->filename,n2->filename)==0));
+ return 0;
+
+}
+
+
+static struct trustee_hash_element * get_trustee_for_name(const struct trustee_name * name) {
+ unsigned int i;
+ if (trustee_hash==NULL) return NULL;
+ for (i=hash(name)%trustee_hash_size;trustee_hash[i].usage;i=(i+1)%trustee_hash_size) {
+ if (trustee_hash[i].usage==1) continue;
+ #ifdef TRUSTEE_DEBUG
+ printk("Comparing in get_trustee_for_name %s, dev %x i is %d", name->filename,(int)name->dev,i);
+ printk(" to %s\n",trustee_hash[i].name.filename);
+ #endif
+ if (trustee_name_cmp(&trustee_hash[i].name,name)) return trustee_hash+i;
+ }
+ return NULL;
+
+}
+
+/* This function does not allocate memory for filename and devname. It should be allocated at calling level */
+static struct trustee_hash_element * getallocate_trustee_for_name(const struct trustee_name * name, int * should_free) {
+
+ struct trustee_hash_element * r,*n;
+ unsigned int i,j,newsize;
+
+
+ lock_kernel();
+ *should_free=1;
+ r=get_trustee_for_name(name);
+ if (r!=NULL) goto unlock_exit;
+
+ if (trustee_hash==NULL){
+#ifdef TRUSTEE_DEBUG
+ printk("Building new trustee hash\n");
+#endif
+ trustee_hash=kmalloc(sizeof(struct trustee_hash_element)*TRUSTEE_INITIAL_HASH_SIZE, GFP_KERNEL);
+ if (trustee_hash==NULL) {
+#ifdef TRUSTEE_DEBUG
+ printk("Can not allocate memory for trustee hash\n");
+#endif
+ goto unlock_exit;
+ }
+ trustee_hash_size=TRUSTEE_INITIAL_HASH_SIZE;
+ trustee_hash_used=0;
+ trustee_hash_deleted=0;
+ for (i=0;i<trustee_hash_size;i++) trustee_hash[i].usage=0;
+ }
+
+ if ((trustee_hash_size*3/4<trustee_hash_used) || (trustee_hash_size-2<trustee_hash_used)) { /*hash needed to be rebuilt, rebuilding hash */
+ newsize=(trustee_hash_deleted*3)>trustee_hash_size?trustee_hash_size:trustee_hash_size*2;
+#ifdef TRUSTEE_DEBUG
+ printk("Rebuilding trustee hash, oldsize: %d, newsize %d, deleted %d\n",trustee_hash_size,newsize, trustee_hash_deleted);
+#endif
+ n=kmalloc(sizeof(struct trustee_hash_element)*newsize, GFP_KERNEL);
+ if (n==NULL) {
+#ifdef TRUSTEE_DEBUG
+ printk("Can not allocate memory for trustee hash\n");
+#endif
+ goto unlock_exit;
+ }
+ for (i=0;i<newsize;i++) n[i].usage=0;
+ trustee_hash_used=0;
+ for (i=0;i<trustee_hash_size;i++) {
+ if (trustee_hash[i].usage==2) {
+ for (j=hash(&trustee_hash[i].name)%newsize;n[j].usage;j=(j+1)%newsize);
+ n[j]=trustee_hash[i];
+ trustee_hash_used++;
+ }
+ }
+ kfree(trustee_hash);
+ trustee_hash=n;
+ trustee_hash_size=newsize;
+ trustee_hash_deleted=0;
+
+
+
+ }
+ for (j=hash(name)%trustee_hash_size;trustee_hash[j].usage==2;j=(j+1)%trustee_hash_size);
+ trustee_hash[j].name=*name;
+ *should_free=0;
+ r=trustee_hash+j;
+ r->list=NULL;
+ r->usage=2;
+#ifdef TRUSTEE_DEBUG
+ printk("Added element to trustee hash: j %d, name : %s\n",j,r->name.filename);
+#endif
+ trustee_hash_used++;
+
+
+ unlock_exit:
+ unlock_kernel();
+ return r;
+
+
+}
+
+int get_trustee_mask_for_name( const struct trustee_name * name,uid_t user,int oldmask,int height)
+{
+ struct trustee_hash_element * e;
+ int m;
+ struct permission_capsule * l;
+ int appl;
+#ifdef TRUSTEE_DEBUG
+ printk("getting trustee mask for %s ", name->filename);
+#endif
+ e=get_trustee_for_name(name);
+ if (e==NULL) {
+#ifdef TRUSTEE_DEBUG
+ printk("Not found, returning old trustee, %x\n",oldmask);
+#endif
+ return oldmask;
+ }
+ for (l=(struct permission_capsule *)e->list;l!=NULL;l=(struct permission_capsule *)l->next) {
+ if ((height<0) && (l->permission.mask & TRUSTEE_ONE_LEVEL_MASK)) continue;
+ appl=((!(l->permission.mask & TRUSTEE_IS_GROUP_MASK)) && (current->fsuid==l->permission.u.uid))
+ ||
+ (((l->permission.mask & TRUSTEE_IS_GROUP_MASK)) && (in_group_p(l->permission.u.gid)))
+ ||
+ (l->permission.mask & TRUSTEE_ALL_MASK);
+ if (l->permission.mask & TRUSTEE_NOT_MASK) appl=!appl;
+ if (!appl) continue;
+ m=l->permission.mask & TRUSTEE_ACL_MASK;
+#ifdef TRUSTEE_DEBUG
+ printk("Found a suitable trustee, mask %x",l->permission.mask);
+#endif
+ if (l->permission.mask & TRUSTEE_ALLOW_DENY_MASK) m <<= TRUSTEE_NUM_ACL_BITS;
+ oldmask=l->permission.mask & TRUSTEE_CLEAR_SET_MASK? oldmask & (~m):oldmask | m;
+
+ }
+#ifdef TRUSTEE_DEBUG
+ printk("The new trustee mask is %x\n",oldmask);
+#endif
+ return oldmask;
+
+}
+
+int get_trustee_mask_for_dentry(struct dentry * dentry,uid_t user) {
+ int oldmask=trustee_default_acl;
+ char * namebuffer, * buf2;
+ int i,j,k;
+ char c;
+ int bufsize;
+ int slashes=1;
+ int slash=1;
+ struct trustee_name name;
+ struct super_block * d_sb;
+ int isdir=S_ISDIR(dentry->d_inode->i_mode);
+ #ifdef TRUSTEE_DEBUG
+ if (user!= TRUSTEE_DEBUG_USER) return trustee_default_acl;
+ printk("Entering get_trustee_mask_for_dentry\n");
+ #endif
+ /* debug */ if (dentry->d_parent==NULL) {
+#ifdef TRUSTEE_DEBUG
+ printk("d_parent is null");
+#endif
+ return trustee_default_acl;
+ }
+ /* debug */ if (dentry->d_name.name==NULL) {
+#ifdef TRUSTEE_DEBUG
+ printk("name is null");
+#endif
+ return trustee_default_acl;
+ }
+ d_sb=dentry->d_sb;
+ if (!d_sb) return trustee_default_acl;
+ namebuffer=kmalloc(TRUSTEE_INITIAL_NAME_BUFFER,GFP_KERNEL);
+ if (!namebuffer) return trustee_default_acl;
+ bufsize=TRUSTEE_INITIAL_NAME_BUFFER;
+ *namebuffer='/';
+ namebuffer[1]=0;
+ i=1;
+ for (;;) {
+ #ifdef TRUSTEE_DEBUG
+ printk("cycle get_trustee_mask_for_dentry, %d\n",i);
+ #endif
+
+ if (IS_ROOT(dentry)) break;
+ j=i+strlen(dentry->d_name.name);
+ #ifdef TRUSTEE_DEBUG
+ printk("j get_trustee_mask_for_dentry %d\n",j);
+ #endif
+
+ if (j+1>=bufsize) {
+ while (j+1>=bufsize) bufsize*=2;
+ buf2=kmalloc(bufsize,GFP_KERNEL);
+ if (!buf2) {
+ kfree(namebuffer);
+ return trustee_default_acl;
+ }
+ strcpy(buf2,namebuffer);
+ kfree(namebuffer);
+ namebuffer=buf2;
+
+ }
+ for (k=0;dentry->d_name.name[k];k++) namebuffer[j-1-k]=dentry->d_name.name[k];
+ i=j;
+ namebuffer[i++]='/';
+ slashes++;
+ dentry=dentry->d_parent;
+ }
+ namebuffer[i]=0;
+ for (j=0;j<i/2;j++) {
+ c=namebuffer[j];
+ namebuffer[j]=namebuffer[i-j-1];
+ namebuffer[i-j-1]=c;
+ }
+ #ifdef TRUSTEE_DEBUG
+ printk("namebuffer is get_trustee_mask_for_dentry %s, i is %d\n", namebuffer,i);
+ #endif
+
+ name.filename=namebuffer;
+ #ifdef TRUSTEE_DEBUG
+ printk("dentry is get_trustee_mask_for_dentry %x, sb is %x", dentry,d_sb);
+ #endif
+
+ name.dev=d_sb->s_dev;
+ name.devname=NULL;
+ j=1;
+ for (;;) {
+ c=namebuffer[j];
+ namebuffer[j]=0;
+ #ifdef TRUSTEE_DEBUG
+ printk("checking in get_trustee_mask_for_dentry %s, j is %d\n", namebuffer,j);
+ #endif
+
+ if (TRUSTEE_HASDEVNAME(name)) {
+ #ifdef TRUSTEE_DEBUG
+ printk("has dev name get_trustee_mask_for_dentry\n");
+ #endif
+
+ if (d_sb->mnt && d_sb->mnt->mnt_devname){
+ name.devname=d_sb->mnt->mnt_devname;
+ oldmask=get_trustee_mask_for_name(&name,user,oldmask,slash-slashes+!isdir);
+ }
+
+ } else oldmask=get_trustee_mask_for_name(&name,user,oldmask,slash-slashes+!isdir);
+ slash++;
+ namebuffer[j]=c;
+ for (j++;(j<i) && (namebuffer[j]!='/');j++) ;
+ if (j>=i) break;
+ }
+ kfree(namebuffer);
+ #ifdef TRUSTEE_DEBUG
+ printk("Exiting get_trustee_mask_for_dentry\n");
+ #endif
+
+ return oldmask;
+
+
+
+}
+
+
+
+
+static int prepare_trustee_name(const struct trustee_command * c, struct trustee_name * name) {
+ name->dev=to_kdev_t(c->dev);
+ name->filename=kmalloc((strlen(c->filename)+1)*sizeof(char),GFP_KERNEL);
+ if (!name->filename) {
+ printk("No memory to allocate for temporary name buffer");
+ return 0;
+ }
+ copy_from_user(name->filename,c->filename,(strlen(c->filename)+1)*sizeof(char));
+
+ if (TRUSTEE_HASDEVNAME(*name)) {
+ name->devname=kmalloc((strlen(c->devname)+1)*sizeof(char),GFP_KERNEL);
+ if (!name->devname) {
+ printk("No memory to allocate for temporary device buffer");
+ kfree(name->filename);
+
+ return 0;
+ }
+ copy_from_user(name->devname,c->devname,(strlen(c->devname)+1)*sizeof(char));
+ }
+ return 1;
+}
+asmlinkage int sys_set_trustee(const struct trustee_command * command) {
+ int r=-ENOSYS, i;
+ struct trustee_name name;
+ struct trustee_hash_element * e;
+ struct permission_capsule * capsule;
+ int should_free;
+ struct trustee_command c;
+ copy_from_user(&c,command,sizeof(c));
+#ifdef TRUSTEE_DEBUG
+ printk("set trustee called, command %d", c.command);
+#endif
+ if ((current->euid!=0) && !capable(CAP_SYS_ADMIN)) return -EACCES;
+ lock_kernel();
+ switch (c.command) {
+ case TRUSTEE_COMMAND_REMOVE_ALL :
+ r=0;
+ if (trustee_hash==NULL) goto unlk;
+ for (i=0;i<trustee_hash_size;i++) {
+ if (trustee_hash[i].usage==2) free_hash_element(trustee_hash[i]);
+ }
+ kfree(trustee_hash);
+ trustee_hash=NULL;
+ goto unlk;
+ case TRUSTEE_COMMAND_REMOVE:
+ if (!prepare_trustee_name(&c,&name)) {
+ r=-ENOMEM;
+ goto unlk;
+ }
+ e=get_trustee_for_name(&name);
+ if (e==NULL) {
+ r=-ENOENT;
+ free_trustee_name(&name);
+ goto unlk;
+ }
+ free_hash_element(*e);
+ trustee_hash_deleted++;
+ free_trustee_name(&name);
+ r=0;
+ goto unlk;
+ case TRUSTEE_COMMAND_REPLACE:
+ if (!prepare_trustee_name(&c,&name)) {
+ r=-ENOMEM;
+ goto unlk;
+ }
+
+ e=getallocate_trustee_for_name(&name,&should_free);
+ if (e==NULL) {
+ r=-ENOMEM;
+ if (should_free) free_trustee_name(&name);
+ goto unlk;
+ }
+ free_hash_element_list(*e);
+ capsule=(struct permission_capsule *)kmalloc(sizeof(struct permission_capsule),GFP_KERNEL);
+ capsule->permission=c.permission;
+ capsule->next=(Ppermission_capsule) e->list;
+ e->list=(struct permission_capsule *)capsule;
+ r=0;
+ if (should_free) free_trustee_name(&name);
+
+ goto unlk;
+
+ case TRUSTEE_COMMAND_ADD:
+ if (!prepare_trustee_name(&c,&name)) {
+ r=-ENOMEM;
+ goto unlk;
+ }
+ e=getallocate_trustee_for_name(&name,&should_free);
+ if (e==NULL) {
+ r=-ENOMEM;
+ if (should_free) free_trustee_name(&name);
+ goto unlk;
+ }
+
+ capsule=(struct permission_capsule *)kmalloc(sizeof(struct permission_capsule),GFP_KERNEL);
+ capsule->permission=c.permission;
+ capsule->next=(Ppermission_capsule)e->list;
+ e->list=(struct permission_capsule *)capsule;
+ r=0;
+ if (should_free) free_trustee_name(&name);
+ goto unlk;
+
+
+ }
+ unlk:
+ unlock_kernel();
+ return r;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- linux/fs/Makefile Thu Jan 3 14:16:35 2002
+++ linux/fs/Makefile Thu Jan 3 14:17:07 2002
@@ -25,6 +25,9 @@
else
O_OBJS += noquot.o
endif
+ifeq ($(CONFIG_TRUSTEES),y)
+O_OBJS += trustee.o
+endif
ifeq ($(CONFIG_CODA_FS),y)
SUB_DIRS += coda
--- linux/arch/i386/kernel/entry.S Thu Jan 3 14:16:35 2002
+++ linux/arch/i386/kernel/entry.S Thu Jan 3 14:17:07 2002
@@ -567,13 +567,49 @@
.long SYMBOL_NAME(sys_ni_syscall) /* streams1 */
.long SYMBOL_NAME(sys_ni_syscall) /* streams2 */
.long SYMBOL_NAME(sys_vfork) /* 190 */
-
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /*195*/ /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /*200*/ /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /*205*/ /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /*210*/ /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /*215*/ /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /*220*/ /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /* reserved */
+ .long SYMBOL_NAME(sys_ni_syscall) /*225*/ /* reserved */
+ .long SYMBOL_NAME(sys_set_trustee)
+ .long SYMBOL_NAME(sys_access_uid)
/*
* NOTE!! This doesn't have to be exact - we just have
* to make sure we have _enough_ of the "sys_ni_syscall"
* entries. Don't panic if you notice that this hasn't
* been shrunk every time we add a new system call.
*/
- .rept NR_syscalls-190
+ .rept NR_syscalls-227
.long SYMBOL_NAME(sys_ni_syscall)
.endr
--- linux/include/asm-i386/unistd.h Thu Jan 3 14:16:35 2002
+++ linux/include/asm-i386/unistd.h Thu Jan 3 14:17:07 2002
@@ -195,6 +195,9 @@
#define __NR_getpmsg 188 /* some people actually want streams */
#define __NR_putpmsg 189 /* some people actually want streams */
#define __NR_vfork 190
+#define __NR_set_trustee 226
+#define __NR_access_uid 227
+
/* user-visible error numbers are in the range -1 - -122: see <asm-i386/errno.h> */
--- linux/include/linux/trustee_struct.h Thu Jan 3 14:16:35 2002
+++ linux/include/linux/trustee_struct.h Thu Jan 3 14:23:57 2002
@@ -0,0 +1,86 @@
+/*
+ * (c) 1999-2000 Vyacheslav Zavadsky
+ */
+
+#ifndef _LINUX_TRUSTEE_STRUCT_H
+
+#define _LINUX_TRUSTEE_STRUCT_H
+#include <linux/types.h>
+
+
+
+#define TRUSTEE_EXECUTE_BIT 0
+#define TRUSTEE_READ_BIT 1
+#define TRUSTEE_WRITE_BIT 2
+#define TRUSTEE_BROWSE_BIT 3
+#define TRUSTEE_READ_DIR_BIT 4
+#define TRUSTEE_USE_UNIX_BIT 5
+#define TRUSTEE_NUM_ACL_BITS (TRUSTEE_USE_UNIX_BIT+1)
+#define TRUSTEE_EXECUTE_MASK (1 << TRUSTEE_EXECUTE_BIT)
+#define TRUSTEE_READ_MASK (1 << TRUSTEE_READ_BIT)
+#define TRUSTEE_WRITE_MASK (1 << TRUSTEE_WRITE_BIT)
+#define TRUSTEE_BROWSE_MASK (1 << TRUSTEE_BROWSE_BIT)
+#define TRUSTEE_READ_DIR_MASK (1 << TRUSTEE_READ_DIR_BIT)
+#define TRUSTEE_USE_UNIX_MASK (1 << TRUSTEE_USE_UNIX_BIT)
+#define TRUSTEE_ACL_MASK ((1 << TRUSTEE_NUM_ACL_BITS)-1)
+
+#define TRUSTEE_ALLOW_DENY_BIT 7
+#define TRUSTEE_IS_GROUP_BIT 6
+#define TRUSTEE_CLEAR_SET_BIT 8
+#define TRUSTEE_ONE_LEVEL_BIT 9
+#define TRUSTEE_NOT_BIT 10
+#define TRUSTEE_ALL_BIT 11
+#define TRUSTEE_ALLOW_DENY_MASK (1 << TRUSTEE_ALLOW_DENY_BIT) /* set if deny */
+#define TRUSTEE_IS_GROUP_MASK (1 << TRUSTEE_IS_GROUP_BIT)
+#define TRUSTEE_CLEAR_SET_MASK (1 << TRUSTEE_CLEAR_SET_BIT) /* set if clear */
+#define TRUSTEE_ONE_LEVEL_MASK (1 << TRUSTEE_ONE_LEVEL_BIT)
+#define TRUSTEE_NOT_MASK (1 << TRUSTEE_NOT_BIT)
+#define TRUSTEE_ALL_MASK (1 << TRUSTEE_ALL_BIT)
+
+#define trustee_acl __u16
+#define trustee_default_acl TRUSTEE_USE_UNIX_MASK
+
+
+
+
+struct trustee_permission {
+ trustee_acl mask;
+ union {
+ __kernel_uid_t uid;
+ __kernel_gid_t gid;
+ } u;
+};
+
+
+
+struct trustee_command {
+ int command;
+ struct trustee_permission permission;
+ int dev;
+ char * filename;
+ char * devname;
+};
+
+
+
+#define TRUSTEE_HASDEVNAME(TNAME) (MAJOR((TNAME).dev)==0)
+
+#define TRUSTEE_COMMAND_ADD 1
+#define TRUSTEE_COMMAND_REPLACE 2
+#define TRUSTEE_COMMAND_REMOVE_ALL 3
+#define TRUSTEE_COMMAND_REMOVE 4
+
+#endif
+
+
+
+
+
+
+
+
+
+
+
+
+
--- linux/Documentation/Configure.help Thu Jan 3 14:16:35 2002
+++ linux/Documentation/Configure.help Thu Jan 3 14:17:07 2002
@@ -14423,6 +14423,10 @@
Saying M will compile this driver as a module (planb.o).
+Linux trustees (ACL) support
+CONFIG_TRUSTEES
+ This code allow to use special objects "trustees" to manage rights to files and directories. See http://www.braysystems.com/linux/trustees.html
+
#
# ARM options
#
--- linux/arch/alpha/kernel/entry.S Thu Jan 3 14:16:35 2002
+++ linux/arch/alpha/kernel/entry.S Thu Jan 3 14:17:07 2002
@@ -1154,3 +1154,6 @@
.quad sys_ni_syscall
.quad sys_ni_syscall /* 375 */
.quad sys_pciconfig_iobase
+ .quad sys_set_trustee
+ .quad sys_access_uid
+
\ No newline at end of file
--- linux/arch/arm/kernel/calls.S Thu Jan 3 14:16:35 2002
+++ linux/arch/arm/kernel/calls.S Thu Jan 3 14:17:07 2002
@@ -200,8 +200,10 @@
.long SYMBOL_NAME(sys_ni_syscall)
.long SYMBOL_NAME(sys_ni_syscall)
/* 190 */ .long SYMBOL_NAME(sys_vfork_wrapper)
+ .long SYMBOL_NAME(sys_set_trustee)
+ .long SYMBOL_NAME(sys_access_uid)
- .rept NR_syscalls-186
+ .rept NR_syscalls-192
.long SYMBOL_NAME(sys_ni_syscall)
.endr
#endif
--- linux/include/asm-arm/unistd.h Thu Jan 3 14:16:35 2002
+++ linux/include/asm-arm/unistd.h Thu Jan 3 14:17:07 2002
@@ -195,9 +195,10 @@
#define __NR_capset (__NR_SYSCALL_BASE+185)
#define __NR_sigaltstack (__NR_SYSCALL_BASE+186)
#define __NR_sendfile (__NR_SYSCALL_BASE+187)
- /* 188 reserved */
- /* 189 reserved */
+
#define __NR_vfork (__NR_SYSCALL_BASE+190)
+#define __NR_set_trustee (__NR_SYSCALL_BASE+191)
+#define __NR_access_uid (__NR_SYSCALL_BASE+192)
#define __sys2(x) #x
#define __sys1(x) __sys2(x)
--- linux/arch/m68k/kernel/entry.S Thu Jan 3 14:16:35 2002
+++ linux/arch/m68k/kernel/entry.S Thu Jan 3 14:17:07 2002
@@ -631,7 +631,9 @@
.long SYMBOL_NAME(sys_ni_syscall) /* streams1 */
.long SYMBOL_NAME(sys_ni_syscall) /* streams2 */
.long SYMBOL_NAME(sys_vfork) /* 190 */
+ .long SYMBOL_NAME(sys_set_trustee)
+ .long SYMBOL_NAME(sys_access_uid)
.rept NR_syscalls-(.-SYMBOL_NAME(sys_call_table))/4
- .long SYMBOL_NAME(sys_ni_syscall)
+ .long SYMBOL_NAME(sys_access_uid)
.endr
--- linux/include/asm-m68k/unistd.h Thu Jan 3 14:16:35 2002
+++ linux/include/asm-m68k/unistd.h Thu Jan 3 14:17:07 2002
@@ -194,6 +194,9 @@
#define __NR_getpmsg 188 /* some people actually want streams */
#define __NR_putpmsg 189 /* some people actually want streams */
#define __NR_vfork 190
+#define __NR_set_trustee 191
+#define __NR_access_uid 192
+
/* user-visible error numbers are in the range -1 - -122: see
<asm-m68k/errno.h> */
--- linux/arch/mips/kernel/syscalls.h Thu Jan 3 14:16:35 2002
+++ linux/arch/mips/kernel/syscalls.h Thu Jan 3 14:17:07 2002
@@ -225,3 +225,5 @@
SYS(sys_sendfile, 3)
SYS(sys_ni_syscall, 0)
SYS(sys_ni_syscall, 0)
+SYS(sys_set_trustee,1) /* 4210 */
+SYS(sys_access_uid,4)
--- linux/include/asm-mips/unistd.h Thu Jan 3 14:16:35 2002
+++ linux/include/asm-mips/unistd.h Thu Jan 3 14:17:07 2002
@@ -263,6 +263,8 @@
#define __NR_SVR4_CDC_reserved18 (__NR_SVR4 + 238)
#define __NR_SVR4_CDC_reserved19 (__NR_SVR4 + 239)
#define __NR_SVR4_CDC_reserved20 (__NR_SVR4 + 240)
+#define __NR_SVR4_set_trustee (__NR_SVR4 + 210)
+#define __NR_SVR4_access_uid (__NR_SVR4 + 211)
/*
* SYS V syscalls are in the range from 1000 to 1999
--- linux/arch/ppc/kernel/misc.S Thu Jan 3 14:16:35 2002
+++ linux/arch/ppc/kernel/misc.S Thu Jan 3 14:17:07 2002
@@ -1070,6 +1070,9 @@
.long sys_pciconfig_write /* 199 */
.long sys_pciconfig_iobase /* 200 */
.long sys_ni_syscall /* 201 - reserved - MacOnLinux - new */
- .rept NR_syscalls-201
+ .long sys_set_trustee /* 202 */
+ .long sys_access_uid /*203*/
+
+ .rept NR_syscalls-203
.long sys_ni_syscall
.endr
--- linux/include/asm-ppc/unistd.h Thu Jan 3 14:16:35 2002
+++ linux/include/asm-ppc/unistd.h Thu Jan 3 14:17:07 2002
@@ -199,6 +199,8 @@
#define __NR_pciconfig_write 199
#define __NR_pciconfig_iobase 200
#define __NR_multiplexer 201
+#define __NR_set_trustee 202
+#define __NR_access_uid 203
#define __NR(n) #n
--- linux/arch/sparc/kernel/systbls.S Thu Jan 3 14:16:35 2002
+++ linux/arch/sparc/kernel/systbls.S Thu Jan 3 14:17:07 2002
@@ -70,7 +70,7 @@
/*240*/ .long sys_munlockall, sys_sched_setparam, sys_sched_getparam, sys_sched_setscheduler, sys_sched_getscheduler
/*245*/ .long sys_sched_yield, sys_sched_get_priority_max, sys_sched_get_priority_min, sys_sched_rr_get_interval, sys_nanosleep
/*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
-/*255*/ .long sys_aplib, sys_nis_syscall
+/*255*/ .long sys_aplib, sys_nis_syscall, sys_set_trustee, sys_access_uid
#ifdef CONFIG_SUNOS_EMUL
/* Now the SunOS syscall table. */
--- linux/include/asm-sparc/unistd.h Thu Jan 3 14:16:35 2002
+++ linux/include/asm-sparc/unistd.h Thu Jan 3 14:17:07 2002
@@ -271,6 +271,8 @@
#define __NR_fdatasync 253
#define __NR_nfsservctl 254
#define __NR_aplib 255
+#define __NR_set_trustee 257
+#define __NR_access_uid 258
#define _syscall0(type,name) \
type name(void) \
--- linux/arch/sparc64/kernel/systbls.S Thu Jan 3 14:16:35 2002
+++ linux/arch/sparc64/kernel/systbls.S Thu Jan 3 14:17:07 2002
@@ -129,7 +129,7 @@
/*240*/ .word sys_munlockall, sys_sched_setparam, sys_sched_getparam, sys_sched_setscheduler, sys_sched_getscheduler
.word sys_sched_yield, sys_sched_get_priority_max, sys_sched_get_priority_min, sys_sched_rr_get_interval, sys_nanosleep
/*250*/ .word sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
- .word sys_aplib
+ .word sys_aplib, sys_set_trustee, sys_access_uid
#if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
defined(CONFIG_SOLARIS_EMUL_MODULE)
--- linux/include/asm-sparc64/unistd.h Thu Jan 3 14:16:35 2002
+++ linux/include/asm-sparc64/unistd.h Thu Jan 3 14:17:07 2002
@@ -271,6 +271,8 @@
#define __NR_fdatasync 253
#define __NR_nfsservctl 254
#define __NR_aplib 255
+#define __NR_set_trustee 256
+#define __NR_access_uid 257
#define _syscall0(type,name) \
type name(void) \
--- linux/CREDITS Thu Jan 3 14:16:35 2002
+++ linux/CREDITS Thu Jan 3 14:17:07 2002
@@ -2478,6 +2478,15 @@
S: Tokyo 153
S: Japan
+N: Vyacheslav Zavadsky
+E: zavadsky@braysystems.com
+D: Linux trustees code
+S: Vasnetcova 11-43
+S: Minsk, 220107
+S: BELARUS
+
+
+
N: Orest Zborowski
E: orestz@eskimo.com
D: XFree86 and kernel development
--- linux/fs/exec.c Thu Jan 3 14:16:35 2002
+++ linux/fs/exec.c Thu Jan 3 14:19:14 2002
@@ -547,7 +547,7 @@
flush_thread();
if (bprm->e_uid != current->euid || bprm->e_gid != current->egid ||
- permission(bprm->dentry->d_inode, MAY_READ)) {
+ permission_dentry(bprm->dentry, MAY_READ)) {
bprm->dumpable = 0;
current->dumpable = 0;
}
@@ -594,7 +594,7 @@
return -EACCES;
if (!inode->i_sb)
return -EACCES;
- if ((retval = permission(inode, MAY_EXEC)) != 0)
+ if ((retval = permission_dentry( bprm->dentry, MAY_EXEC)) != 0)
return retval;
/* better not execute files which are being written to */
if (inode->i_writecount > 0)
--- linux/fs/nfsd/vfs.c Thu Jan 3 14:16:35 2002
+++ linux/fs/nfsd/vfs.c Thu Jan 3 14:17:07 2002
@@ -1751,11 +1751,11 @@
cap_clear(current->cap_effective);
}
- err = permission(inode, acc & (MAY_READ|MAY_WRITE|MAY_EXEC));
+ err = permission_dentry(dentry, acc & (MAY_READ|MAY_WRITE|MAY_EXEC));
/* Allow read access to binaries even when mode 111 */
if (err == -EACCES && S_ISREG(inode->i_mode) && acc == MAY_READ)
- err = permission(inode, MAY_EXEC);
+ err = permission_dentry(dentry, MAY_EXEC);
if (current->fsuid != 0)
current->cap_effective = saved_cap;
--- linux/fs/super.c Thu Jan 3 14:16:35 2002
+++ linux/fs/super.c Thu Jan 3 14:17:07 2002
@@ -108,7 +108,7 @@
sema_init(&lptr->mnt_dquot.dqio_sem, 1);
sema_init(&lptr->mnt_dquot.dqoff_sem, 1);
lptr->mnt_dquot.flags = 0;
-
+ sb->mnt=lptr;
/* N.B. Is it really OK to have a vfsmount without names? */
if (dev_name && !IS_ERR(tmp = getname(dev_name))) {
name = (char *) kmalloc(strlen(tmp)+1, GFP_KERNEL);
@@ -162,6 +162,7 @@
if (vfsmnttail->mnt_dev == dev)
vfsmnttail = lptr;
}
+ tofree->mnt_sb->mnt=NULL;
if (tofree == mru_vfsmnt)
mru_vfsmnt = NULL;
kfree(tofree->mnt_devname);
--- linux/fs/proc/link.c Thu Jan 3 14:16:35 2002
+++ linux/fs/proc/link.c Thu Jan 3 14:17:07 2002
@@ -69,7 +69,7 @@
/* We don't need a base pointer in the /proc filesystem */
dput(base);
- error = permission(inode, MAY_EXEC);
+ error = permission_dentry(dentry, MAY_EXEC);
result = ERR_PTR(error);
if (error)
goto out;
--- linux/fs/binfmt_elf.c Thu Jan 3 14:16:35 2002
+++ linux/fs/binfmt_elf.c Thu Jan 3 14:17:07 2002
@@ -547,7 +547,7 @@
retval = PTR_ERR(interpreter_dentry);
if (IS_ERR(interpreter_dentry))
goto out_free_interp;
- retval = permission(interpreter_dentry->d_inode, MAY_EXEC);
+ retval = permission_dentry(interpreter_dentry, MAY_EXEC);
if (retval < 0)
goto out_free_dentry;
retval = read_exec(interpreter_dentry, 0, bprm->buf, 128, 1);
--- linux/kernel/ksyms.c Thu Jan 3 14:16:35 2002
+++ linux/kernel/ksyms.c Thu Jan 3 14:17:07 2002
@@ -37,7 +37,7 @@
#include <linux/poll.h>
#include <linux/mm.h>
#include <linux/capability.h>
-
+#include <linux/fs.h>
#if defined(CONFIG_PROC_FS)
#include <linux/proc_fs.h>
#endif
@@ -446,5 +446,7 @@
EXPORT_SYMBOL(_stext);
EXPORT_SYMBOL(_etext);
EXPORT_SYMBOL(module_list);
-
+#ifdef CONFIG_TRUSTEES
+EXPORT_SYMBOL(permission_dentry);
+#endif
--- linux/fs/proc/root.c Thu Jan 3 14:16:35 2002
+++ linux/fs/proc/root.c Thu Jan 3 14:17:07 2002
@@ -21,7 +21,9 @@
#ifdef CONFIG_ZORRO
#include <linux/zorro.h>
#endif
-
+#ifdef CONFIG_TRUSTEES
+#include <linux/trustee.h>
+#endif
/*
* Offset of the first process in the /proc root directory..
*/
@@ -750,7 +752,9 @@
#ifdef CONFIG_PROC_DEVICETREE
proc_device_tree_init();
#endif
-
+#ifdef CONFIG_TRUSTEES
+ proc_trustee_init();
+#endif
proc_bus = create_proc_entry("bus", S_IFDIR, 0);
}
--- linux/fs/proc/trustee.c Thu Jan 3 14:16:35 2002
+++ linux/fs/proc/trustee.c Thu Jan 3 14:17:07 2002
@@ -0,0 +1,67 @@
+#include <asm/uaccess.h>
+#include <asm/unistd.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/proc_fs.h>
+#include <linux/stat.h>
+#include <asm/bitops.h>
+
+/*
+ Daniel Podlejski <underley@debian.pl>, 2001.03.06
+ trustee syscall number is now avaliable
+ in /proc/trustee/syscall
+*/
+
+/*
+ * The /proc/trustee directory inodes...
+ */
+
+static struct proc_dir_entry *proc_trustee_syscall;
+
+/*
+ * This is the handler for /proc/trustee/syscall
+ */
+
+static int trustee_syscall_read_proc(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ int len = 0;
+ off_t begin = 0;
+
+ len += sprintf(page + len, "%d\n", __NR_set_trustee);
+
+ if (off >= len+begin) return 0;
+
+ *start = page + (off - begin);
+
+ return ((count < begin + len - off) ? count : begin + len - off);
+}
+
+/*
+ * Called by proc_root_init() to initialize the /proc/trustee subtree
+ */
+
+__initfunc(void proc_trustee_init(void))
+{
+ struct proc_dir_entry *ent;
+
+ ent = create_proc_entry("trustee", S_IFDIR, 0);
+ if (!ent) return;
+
+ ent = create_proc_entry("trustee/syscall", 0, 0);
+ ent->read_proc = trustee_syscall_read_proc;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
--- linux/fs/proc/Makefile Thu Jan 3 14:16:35 2002
+++ linux/fs/proc/Makefile Thu Jan 3 14:17:07 2002
@@ -27,5 +27,8 @@
ifeq ($(CONFIG_PROC_DEVICETREE),y)
O_OBJS += proc_devtree.o
endif
+ifeq ($(CONFIG_TRUSTEES),y)
+O_OBJS += trustee.o
+endif
include $(TOPDIR)/Rules.make
|