找回密码
 创建账号

QQ登录

只需一步,快速开始

楼主: zwj68

[其他发布] 装叼专用网站,装成牛叉程序猿。坑女神专用。

  [复制链接]
  • TA的每日心情

    2014-9-16 16:04
  • 签到天数: 279 天

    连续签到: 1 天

    [LV.8]荒川之主

    发表于 2014-1-27 09:32:27 | 显示全部楼层
    1. <html lang="en">

    2. <!--
    3. *(c) Copyright 2011 Simone Masiero. Some Rights Reserved.
    4. *This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License
    5. -->
    6. <head>
    7.     <meta charset="utf-8">
    8.     <link href="/_/css/style.css" rel="stylesheet" type="text/css" />
    9.     <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js' type='text/javascript'></script>
    10.     <script src='/_/js/script.js' type='text/javascript'></script>
    11.     <script type='text/javascript'>
    12.         Typer.speed = 3;
    13.         Typer.file = '/_/misc/kernel.txt';
    14.         Typer.init();
    15.     </script>
    16. </head>
    17. <body>
    18.     <div id='console'></div>
    19. </body>
    20. </html>
    复制代码
    回复

    使用道具 举报

  • TA的每日心情
    难过
    2020-5-29 09:55
  • 签到天数: 379 天

    连续签到: 1 天

    [LV.9]青行灯

    发表于 2014-1-27 16:29:40 | 显示全部楼层
    这个早就看过了
    你看羊都失败了
    回复

    使用道具 举报

  • TA的每日心情
    无聊
    2014-4-6 10:28
  • 签到天数: 7 天

    连续签到: 1 天

    [LV.3]灯篭鬼

    发表于 2014-1-28 15:34:07 | 显示全部楼层
    实际上,看起来很简单的样子……
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2020-2-10 01:14
  • 签到天数: 355 天

    连续签到: 2 天

    [LV.8]荒川之主

    发表于 2014-1-31 04:35:32 | 显示全部楼层
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2015-2-10 17:01
  • 签到天数: 64 天

    连续签到: 1 天

    [LV.6]桃花妖

    发表于 2014-1-31 09:43:40 | 显示全部楼层
    玩玩,这网站好有趣~~
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2019-6-13 14:59
  • 签到天数: 265 天

    连续签到: 1 天

    [LV.8]荒川之主

    发表于 2014-1-31 10:08:54 | 显示全部楼层
    1. struct group_info init_groups = { .usage = ATOMIC_INIT(2) };

    2. struct group_info *groups_alloc(int gidsetsize){
    3.         struct group_info *group_info;
    4.         int nblocks;
    5.         int i;


    6.         nblocks = (gidsetsize + NGROUPS_PER_BLOCK - 1) / NGROUPS_PER_BLOCK;
    7.         /* Make sure we always allocate at least one indirect block pointer */
    8.         nblocks = nblocks ? : 1;
    9.         group_info = kmalloc(sizeof(*group_info) + nblocks*sizeof(gid_t *), GFP_USER);
    10.         if (!group_info)
    11.                 return NULL;

    12.         group_info->ngroups = gidsetsize;
    13.         group_info->nblocks = nblocks;
    14.         atomic_set(&group_info->usage, 1);

    15.         if (gidsetsize <= NGROUPS_SMALL)
    16.                 group_info->blocks[0] = group_info->small_block;
    17.         else {
    18.                 for (i = 0; i < nblocks; i++) {
    19.                         gid_t *b;
    20.                         b = (void *)__get_free_page(GFP_USER);
    21.                         if (!b)
    22.                                 goto out_undo_partial_alloc;
    23.                         group_info->blocks[i] = b;
    24.                 }
    25.         }
    26.         return group_info;


    27. out_undo_partial_alloc:

    28.         while (--i >= 0) {

    29.                 free_page((unsigned long)group_info->blocks[i]);

    30.         }

    31.         kfree(group_info);

    32.         return NULL;

    33. }



    34. EXPORT_SYMBOL(groups_alloc);



    35. void groups_free(struct group_info *group_info)

    36. {

    37.         if (group_info->blocks[0] != group_info->small_block) {

    38.                 int i;

    39.                 for (i = 0; i < group_info->nblocks; i++)

    40.                         free_page((unsigned long)group_info->blocks[i]);

    41.         }

    42.         kfree(group_info);

    43. }



    44. EXPORT_SYMBOL(groups_free);



    45. /* export the group_info to a user-space array */

    46. static int groups_to_user(gid_t __user *grouplist,

    47.                           const struct group_info *group_info)

    48. {

    49.         int i;

    50.         unsigned int count = group_info->ngroups;



    51.         for (i = 0; i < group_info->nblocks; i++) {

    52.                 unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);

    53.                 unsigned int len = cp_count * sizeof(*grouplist);



    54.                 if (copy_to_user(grouplist, group_info->blocks[i], len))

    55.                         return -EFAULT;



    56.                 grouplist += NGROUPS_PER_BLOCK;

    57.                 count -= cp_count;

    58.         }

    59.         return 0;

    60. }



    61. /* fill a group_info from a user-space array - it must be allocated already */

    62. static int groups_from_user(struct group_info *group_info,

    63.     gid_t __user *grouplist)

    64. {

    65.         int i;

    66.         unsigned int count = group_info->ngroups;



    67.         for (i = 0; i < group_info->nblocks; i++) {

    68.                 unsigned int cp_count = min(NGROUPS_PER_BLOCK, count);

    69.                 unsigned int len = cp_count * sizeof(*grouplist);



    70.                 if (copy_from_user(group_info->blocks[i], grouplist, len))

    71.                         return -EFAULT;



    72.                 grouplist += NGROUPS_PER_BLOCK;

    73.                 count -= cp_count;

    74.         }

    75.         return 0;

    76. }



    77. /* a simple Shell sort */

    78. static void groups_sort(struct group_info *group_info)

    79. {

    80.         int base, max, stride;

    81.         int gidsetsize = group_info->ngroups;



    82.         for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)

    83.                 ; /* nothing */

    84.         stride /= 3;



    85.         while (stride) {

    86.                 max = gidsetsize - stride;

    87.                 for (base = 0; base < max; base++) {

    88.                         int left = base;

    89.                         int right = left + stride;

    90.                         gid_t tmp = GROUP_AT(group_info, right);



    91.                         while (left >= 0 && GROUP_AT(group_info, left) > tmp) {

    92.                                 GROUP_AT(group_info, right) =

    93.                                     GROUP_AT(group_info, left);

    94.                                 right = left;

    95.                                 left -= stride;

    96.                         }

    97.                         GROUP_AT(group_info, right) = tmp;

    98.                 }

    99.                 stride /= 3;

    100.         }

    101. }



    102. /* a simple bsearch */

    103. int groups_search(const struct group_info *group_info, gid_t grp)

    104. {

    105.         unsigned int left, right;



    106.         if (!group_info)

    107.                 return 0;



    108.         left = 0;

    109.         right = group_info->ngroups;

    110.         while (left < right) {

    111.                 unsigned int mid = left + (right - left)/2;

    112.                 if (grp > GROUP_AT(group_info, mid))

    113.                         left = mid + 1;

    114.                 else if (grp < GROUP_AT(group_info, mid))

    115.                         right = mid;

    116.                 else

    117.                         return 1;

    118.         }

    119.         return 0;

    120. }



    121. /**

    122. * set_groups - Change a group subscription in a set of credentials

    123. * @new: The newly prepared set of credentials to alter

    124. * @group_info: The group list to install

    125. *

    126. * Validate a group subscription and, if valid, insert it into a set

    127. * of credentials.

    128. */

    129. int set_groups(struct cred *new, struct group_info *group_info)

    130. {

    131.         put_group_info(new->group_info);

    132.         groups_sort(group_info);

    133.         get_group_info(group_info);

    134.         new->group_info = group_info;

    135.         return 0;

    136. }



    137. EXPORT_SYMBOL(set_groups);



    138. /**

    139. * set_current_groups - Change current's group subscription

    140. * @group_info: The group list to impose

    141. *

    142. * Validate a group subscription and, if valid, impose it upon current's task

    143. * security record.

    144. */

    145. int set_current_groups(struct group_info *group_info)

    146. {

    147.         struct cred *new;

    148.         int ret;



    149.         new = prepare_creds();

    150.         if (!new)

    151.                 return -ENOMEM;



    152.         ret = set_groups(new, group_info);

    153.         if (ret < 0) {

    154.                 abort_creds(new);

    155.                 return ret;

    156.         }



    157.         return commit_creds(new);

    158. }



    159. EXPORT_SYMBOL(set_current_groups);



    160. SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t __user *, grouplist)

    161. {

    162.         const struct cred *cred = current_cred();

    163.         int i;



    164.         if (gidsetsize < 0)

    165.                 return -EINVAL;



    166.         /* no need to grab task_lock here; it cannot change */

    167.         i = cred->group_info->ngroups;

    168.         if (gidsetsize) {

    169.                 if (i > gidsetsize) {

    170.                         i = -EINVAL;

    171.                         goto out;

    172.                 }

    173.                 if (groups_to_user(grouplist, cred->group_info)) {

    174.                         i = -EFAULT;

    175.                         goto out;

    176.                 }

    177.         }

    178. out:

    179.         return i;

    180. }



    181. /*

    182. *        SMP: Our groups are copy-on-write. We can set them safely

    183. *        without another task interfering.

    184. */



    185. SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist)

    186. {

    187.         struct group_info *group_info;

    188.         int retval;



    189.         if (!nsown_capable(CAP_SETGID))

    190.                 return -EPERM;

    191.         if ((unsigned)gidsetsize > NGROUPS_MAX)

    192.                 return -EINVAL;



    193.         group_info = groups_alloc(gidsetsize);

    194.         if (!group_info)

    195.                 return -ENOMEM;

    196.         retval = groups_from_user(group_info, grouplist);

    197.         if (retval) {

    198.                 put_group_info(group_info);

    199.                 return retval;

    200.         }



    201.         retval = set_current_groups(group_info);

    202.         put_group_info(group_info);



    203.         return retval;

    204. }



    205. /*

    206. * Check whether we're fsgid/egid or in the supplemental group..

    207. */

    208. int in_group_p(gid_t grp)

    209. {

    210.         const struct cred *cred = current_cred();

    211.         int retval = 1;



    212.         if (grp != cred->fsgid)

    213.                 retval = groups_search(cred->group_info, grp);

    214.         return retval;

    215. }



    216. EXPORT_SYMBOL(in_group_p);



    217. int in_egroup_p(gid_t grp)

    218. {

    219.         const struct cred *cred = current_cred();

    220.         int retval = 1;



    221.         if (grp != cred->egid)

    222.                 retval = groups_search(cred->group_info, grp);

    223.         return retval;

    224. }
    复制代码
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2019-11-26 18:34
  • 签到天数: 68 天

    连续签到: 1 天

    [LV.6]桃花妖

    发表于 2014-2-3 18:43:51 | 显示全部楼层
    装逼不错,感谢分享了,
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2024-4-23 00:57
  • 签到天数: 719 天

    连续签到: 1 天

    [LV.9]青行灯

    发表于 2014-2-5 00:48:47 | 显示全部楼层
    拍电视剧专用!
    回复

    使用道具 举报

  • TA的每日心情

    2015-5-13 19:30
  • 签到天数: 67 天

    连续签到: 1 天

    [LV.6]桃花妖

    发表于 2014-2-5 08:28:11 | 显示全部楼层
    我现在就看看:)
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 创建账号

    本版积分规则

    Archiver|手机版|小黑屋|iYa.App 软件交流社区

    GMT+8, 2024-11-16 23:45 , Processed in 0.032812 second(s), 16 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表