root/kernel/sys.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_ni_syscall
  2. proc_sel
  3. sys_setpriority
  4. sys_getpriority
  5. sys_profil
  6. sys_ftime
  7. sys_break
  8. sys_stty
  9. sys_gtty
  10. sys_prof
  11. sys_reboot
  12. ctrl_alt_del
  13. sys_setregid
  14. sys_setgid
  15. sys_acct
  16. sys_phys
  17. sys_lock
  18. sys_mpx
  19. sys_ulimit
  20. sys_old_syscall
  21. sys_setreuid
  22. sys_setuid
  23. sys_setfsuid
  24. sys_setfsgid
  25. sys_times
  26. sys_brk
  27. sys_setpgid
  28. sys_getpgid
  29. sys_getpgrp
  30. sys_setsid
  31. sys_getgroups
  32. sys_setgroups
  33. in_group_p
  34. sys_newuname
  35. sys_uname
  36. sys_olduname
  37. sys_sethostname
  38. sys_gethostname
  39. sys_setdomainname
  40. sys_getrlimit
  41. sys_setrlimit
  42. getrusage
  43. sys_getrusage
  44. sys_umask

   1 /*
   2  *  linux/kernel/sys.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <linux/errno.h>
   8 #include <linux/sched.h>
   9 #include <linux/kernel.h>
  10 #include <linux/times.h>
  11 #include <linux/utsname.h>
  12 #include <linux/param.h>
  13 #include <linux/resource.h>
  14 #include <linux/signal.h>
  15 #include <linux/string.h>
  16 #include <linux/ptrace.h>
  17 #include <linux/stat.h>
  18 #include <linux/mman.h>
  19 #include <linux/mm.h>
  20 
  21 #include <asm/segment.h>
  22 #include <asm/io.h>
  23 
  24 /*
  25  * this indicates whether you can reboot with ctrl-alt-del: the default is yes
  26  */
  27 static int C_A_D = 1;
  28 
  29 extern void adjust_clock(void);
  30 
  31 #define PZERO   15
  32 
  33 asmlinkage int sys_ni_syscall(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35         return -ENOSYS;
  36 }
  37 
  38 static int proc_sel(struct task_struct *p, int which, int who)
     /* [previous][next][first][last][top][bottom][index][help] */
  39 {
  40         switch (which) {
  41                 case PRIO_PROCESS:
  42                         if (!who && p == current)
  43                                 return 1;
  44                         return(p->pid == who);
  45                 case PRIO_PGRP:
  46                         if (!who)
  47                                 who = current->pgrp;
  48                         return(p->pgrp == who);
  49                 case PRIO_USER:
  50                         if (!who)
  51                                 who = current->uid;
  52                         return(p->uid == who);
  53         }
  54         return 0;
  55 }
  56 
  57 asmlinkage int sys_setpriority(int which, int who, int niceval)
     /* [previous][next][first][last][top][bottom][index][help] */
  58 {
  59         struct task_struct **p;
  60         int error = ESRCH;
  61         int priority;
  62 
  63         if (which > 2 || which < 0)
  64                 return -EINVAL;
  65 
  66         if ((priority = PZERO - niceval) <= 0)
  67                 priority = 1;
  68 
  69         for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
  70                 if (!*p || !proc_sel(*p, which, who))
  71                         continue;
  72                 if ((*p)->uid != current->euid &&
  73                         (*p)->uid != current->uid && !suser()) {
  74                         error = EPERM;
  75                         continue;
  76                 }
  77                 if (error == ESRCH)
  78                         error = 0;
  79                 if (priority > (*p)->priority && !suser())
  80                         error = EACCES;
  81                 else
  82                         (*p)->priority = priority;
  83         }
  84         return -error;
  85 }
  86 
  87 asmlinkage int sys_getpriority(int which, int who)
     /* [previous][next][first][last][top][bottom][index][help] */
  88 {
  89         struct task_struct **p;
  90         int max_prio = 0;
  91 
  92         if (which > 2 || which < 0)
  93                 return -EINVAL;
  94 
  95         for(p = &LAST_TASK; p > &FIRST_TASK; --p) {
  96                 if (!*p || !proc_sel(*p, which, who))
  97                         continue;
  98                 if ((*p)->priority > max_prio)
  99                         max_prio = (*p)->priority;
 100         }
 101         return(max_prio ? max_prio : -ESRCH);
 102 }
 103 
 104 asmlinkage int sys_profil(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 105 {
 106         return -ENOSYS;
 107 }
 108 
 109 asmlinkage int sys_ftime(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 110 {
 111         return -ENOSYS;
 112 }
 113 
 114 asmlinkage int sys_break(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 115 {
 116         return -ENOSYS;
 117 }
 118 
 119 asmlinkage int sys_stty(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121         return -ENOSYS;
 122 }
 123 
 124 asmlinkage int sys_gtty(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 125 {
 126         return -ENOSYS;
 127 }
 128 
 129 asmlinkage int sys_prof(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 130 {
 131         return -ENOSYS;
 132 }
 133 
 134 extern void hard_reset_now(void);
 135 extern asmlinkage sys_kill(int, int);
 136 
 137 /*
 138  * Reboot system call: for obvious reasons only root may call it,
 139  * and even root needs to set up some magic numbers in the registers
 140  * so that some mistake won't make this reboot the whole machine.
 141  * You can also set the meaning of the ctrl-alt-del-key here.
 142  *
 143  * reboot doesn't sync: do that yourself before calling this.
 144  */
 145 asmlinkage int sys_reboot(int magic, int magic_too, int flag)
     /* [previous][next][first][last][top][bottom][index][help] */
 146 {
 147         if (!suser())
 148                 return -EPERM;
 149         if (magic != 0xfee1dead || magic_too != 672274793)
 150                 return -EINVAL;
 151         if (flag == 0x01234567)
 152                 hard_reset_now();
 153         else if (flag == 0x89ABCDEF)
 154                 C_A_D = 1;
 155         else if (!flag)
 156                 C_A_D = 0;
 157         else if (flag == 0xCDEF0123) {
 158                 printk(KERN_EMERG "System halted\n");
 159                 sys_kill(-1, SIGKILL);
 160                 do_exit(0);
 161         } else
 162                 return -EINVAL;
 163         return (0);
 164 }
 165 
 166 /*
 167  * This function gets called by ctrl-alt-del - ie the keyboard interrupt.
 168  * As it's called within an interrupt, it may NOT sync: the only choice
 169  * is whether to reboot at once, or just ignore the ctrl-alt-del.
 170  */
 171 void ctrl_alt_del(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 172 {
 173         if (C_A_D)
 174                 hard_reset_now();
 175         else
 176                 send_sig(SIGINT,task[1],1);
 177 }
 178         
 179 
 180 /*
 181  * Unprivileged users may change the real gid to the effective gid
 182  * or vice versa.  (BSD-style)
 183  *
 184  * If you set the real gid at all, or set the effective gid to a value not
 185  * equal to the real gid, then the saved gid is set to the new effective gid.
 186  *
 187  * This makes it possible for a setgid program to completely drop its
 188  * privileges, which is often a useful assertion to make when you are doing
 189  * a security audit over a program.
 190  *
 191  * The general idea is that a program which uses just setregid() will be
 192  * 100% compatible with BSD.  A program which uses just setgid() will be
 193  * 100% compatible with POSIX w/ Saved ID's. 
 194  */
 195 asmlinkage int sys_setregid(gid_t rgid, gid_t egid)
     /* [previous][next][first][last][top][bottom][index][help] */
 196 {
 197         int old_rgid = current->gid;
 198 
 199         if (rgid != (gid_t) -1) {
 200                 if ((old_rgid == rgid) ||
 201                     (current->egid==rgid) ||
 202                     suser())
 203                         current->gid = rgid;
 204                 else
 205                         return(-EPERM);
 206         }
 207         if (egid != (gid_t) -1) {
 208                 if ((old_rgid == egid) ||
 209                     (current->egid == egid) ||
 210                     (current->sgid == egid) ||
 211                     suser())
 212                         current->egid = egid;
 213                 else {
 214                         current->gid = old_rgid;
 215                         return(-EPERM);
 216                 }
 217         }
 218         if (rgid != (gid_t) -1 ||
 219             (egid != (gid_t) -1 && egid != old_rgid))
 220                 current->sgid = current->egid;
 221         current->fsgid = current->egid;
 222         return 0;
 223 }
 224 
 225 /*
 226  * setgid() is implemented like SysV w/ SAVED_IDS 
 227  */
 228 asmlinkage int sys_setgid(gid_t gid)
     /* [previous][next][first][last][top][bottom][index][help] */
 229 {
 230         if (suser())
 231                 current->gid = current->egid = current->sgid = current->fsgid = gid;
 232         else if ((gid == current->gid) || (gid == current->sgid))
 233                 current->egid = current->fsgid = gid;
 234         else
 235                 return -EPERM;
 236         return 0;
 237 }
 238 
 239 asmlinkage int sys_acct(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 240 {
 241         return -ENOSYS;
 242 }
 243 
 244 asmlinkage int sys_phys(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 245 {
 246         return -ENOSYS;
 247 }
 248 
 249 asmlinkage int sys_lock(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 250 {
 251         return -ENOSYS;
 252 }
 253 
 254 asmlinkage int sys_mpx(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 255 {
 256         return -ENOSYS;
 257 }
 258 
 259 asmlinkage int sys_ulimit(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 260 {
 261         return -ENOSYS;
 262 }
 263 
 264 asmlinkage int sys_old_syscall(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 265 {
 266         return -ENOSYS;
 267 }
 268 
 269 /*
 270  * Unprivileged users may change the real uid to the effective uid
 271  * or vice versa.  (BSD-style)
 272  *
 273  * If you set the real uid at all, or set the effective uid to a value not
 274  * equal to the real uid, then the saved uid is set to the new effective uid.
 275  *
 276  * This makes it possible for a setuid program to completely drop its
 277  * privileges, which is often a useful assertion to make when you are doing
 278  * a security audit over a program.
 279  *
 280  * The general idea is that a program which uses just setreuid() will be
 281  * 100% compatible with BSD.  A program which uses just setuid() will be
 282  * 100% compatible with POSIX w/ Saved ID's. 
 283  */
 284 asmlinkage int sys_setreuid(uid_t ruid, uid_t euid)
     /* [previous][next][first][last][top][bottom][index][help] */
 285 {
 286         int old_ruid = current->uid;
 287 
 288         if (ruid != (uid_t) -1) {
 289                 if ((old_ruid == ruid) || 
 290                     (current->euid==ruid) ||
 291                     suser())
 292                         current->uid = ruid;
 293                 else
 294                         return(-EPERM);
 295         }
 296         if (euid != (uid_t) -1) {
 297                 if ((old_ruid == euid) ||
 298                     (current->euid == euid) ||
 299                     (current->suid == euid) ||
 300                     suser())
 301                         current->euid = euid;
 302                 else {
 303                         current->uid = old_ruid;
 304                         return(-EPERM);
 305                 }
 306         }
 307         if (ruid != (uid_t) -1 ||
 308             (euid != (uid_t) -1 && euid != old_ruid))
 309                 current->suid = current->euid;
 310         current->fsuid = current->euid;
 311         return 0;
 312 }
 313 
 314 /*
 315  * setuid() is implemented like SysV w/ SAVED_IDS 
 316  * 
 317  * Note that SAVED_ID's is deficient in that a setuid root program
 318  * like sendmail, for example, cannot set its uid to be a normal 
 319  * user and then switch back, because if you're root, setuid() sets
 320  * the saved uid too.  If you don't like this, blame the bright people
 321  * in the POSIX committee and/or USG.  Note that the BSD-style setreuid()
 322  * will allow a root program to temporarily drop privileges and be able to
 323  * regain them by swapping the real and effective uid.  
 324  */
 325 asmlinkage int sys_setuid(uid_t uid)
     /* [previous][next][first][last][top][bottom][index][help] */
 326 {
 327         if (suser())
 328                 current->uid = current->euid = current->suid = current->fsuid = uid;
 329         else if ((uid == current->uid) || (uid == current->suid))
 330                 current->fsuid = current->euid = uid;
 331         else
 332                 return -EPERM;
 333         return(0);
 334 }
 335 
 336 /*
 337  * "setfsuid()" sets the fsuid - the uid used for filesystem checks. This
 338  * is used for "access()" and for the NFS daemon (letting nfsd stay at
 339  * whatever uid it wants to). It normally shadows "euid", except when
 340  * explicitly set by setfsuid() or for access..
 341  */
 342 asmlinkage int sys_setfsuid(uid_t uid)
     /* [previous][next][first][last][top][bottom][index][help] */
 343 {
 344         int old_fsuid = current->fsuid;
 345 
 346         if (uid == current->uid || uid == current->euid ||
 347             uid == current->suid || uid == current->fsuid || suser())
 348                 current->fsuid = uid;
 349         return old_fsuid;
 350 }
 351 
 352 /*
 353  * Samma på svenska..
 354  */
 355 asmlinkage int sys_setfsgid(gid_t gid)
     /* [previous][next][first][last][top][bottom][index][help] */
 356 {
 357         int old_fsgid = current->fsgid;
 358 
 359         if (gid == current->gid || gid == current->egid ||
 360             gid == current->sgid || gid == current->fsgid || suser())
 361                 current->fsgid = gid;
 362         return old_fsgid;
 363 }
 364 
 365 asmlinkage int sys_times(struct tms * tbuf)
     /* [previous][next][first][last][top][bottom][index][help] */
 366 {
 367         if (tbuf) {
 368                 int error = verify_area(VERIFY_WRITE,tbuf,sizeof *tbuf);
 369                 if (error)
 370                         return error;
 371                 put_fs_long(current->utime,(unsigned long *)&tbuf->tms_utime);
 372                 put_fs_long(current->stime,(unsigned long *)&tbuf->tms_stime);
 373                 put_fs_long(current->cutime,(unsigned long *)&tbuf->tms_cutime);
 374                 put_fs_long(current->cstime,(unsigned long *)&tbuf->tms_cstime);
 375         }
 376         return jiffies;
 377 }
 378 
 379 asmlinkage unsigned long sys_brk(unsigned long brk)
     /* [previous][next][first][last][top][bottom][index][help] */
 380 {
 381         int freepages;
 382         unsigned long rlim;
 383         unsigned long newbrk, oldbrk;
 384 
 385         if (brk < current->mm->end_code)
 386                 return current->mm->brk;
 387         newbrk = PAGE_ALIGN(brk);
 388         oldbrk = PAGE_ALIGN(current->mm->brk);
 389         if (oldbrk == newbrk)
 390                 return current->mm->brk = brk;
 391 
 392         /*
 393          * Always allow shrinking brk
 394          */
 395         if (brk <= current->mm->brk) {
 396                 current->mm->brk = brk;
 397                 do_munmap(newbrk, oldbrk-newbrk);
 398                 return brk;
 399         }
 400         /*
 401          * Check against rlimit and stack..
 402          */
 403         rlim = current->rlim[RLIMIT_DATA].rlim_cur;
 404         if (rlim >= RLIM_INFINITY)
 405                 rlim = ~0;
 406         if (brk - current->mm->end_code > rlim)
 407                 return current->mm->brk;
 408         /*
 409          * Check against existing mmap mappings.
 410          */
 411         if (find_vma_intersection(current, oldbrk, newbrk+PAGE_SIZE))
 412                 return current->mm->brk;
 413         /*
 414          * stupid algorithm to decide if we have enough memory: while
 415          * simple, it hopefully works in most obvious cases.. Easy to
 416          * fool it, but this should catch most mistakes.
 417          */
 418         freepages = buffermem >> 12;
 419         freepages += nr_free_pages;
 420         freepages += nr_swap_pages;
 421         freepages -= (high_memory - 0x100000) >> 16;
 422         freepages -= (newbrk-oldbrk) >> 12;
 423         if (freepages < 0)
 424                 return current->mm->brk;
 425 #if 0
 426         freepages += current->mm->rss;
 427         freepages -= oldbrk >> 12;
 428         if (freepages < 0)
 429                 return current->mm->brk;
 430 #endif
 431         /*
 432          * Ok, we have probably got enough memory - let it rip.
 433          */
 434         current->mm->brk = brk;
 435         do_mmap(NULL, oldbrk, newbrk-oldbrk,
 436                 PROT_READ|PROT_WRITE|PROT_EXEC,
 437                 MAP_FIXED|MAP_PRIVATE, 0);
 438         return brk;
 439 }
 440 
 441 /*
 442  * This needs some heave checking ...
 443  * I just haven't get the stomach for it. I also don't fully
 444  * understand sessions/pgrp etc. Let somebody who does explain it.
 445  *
 446  * OK, I think I have the protection semantics right.... this is really
 447  * only important on a multi-user system anyway, to make sure one user
 448  * can't send a signal to a process owned by another.  -TYT, 12/12/91
 449  *
 450  * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
 451  * LBT 04.03.94
 452  */
 453 asmlinkage int sys_setpgid(pid_t pid, pid_t pgid)
     /* [previous][next][first][last][top][bottom][index][help] */
 454 {
 455         struct task_struct * p;
 456 
 457         if (!pid)
 458                 pid = current->pid;
 459         if (!pgid)
 460                 pgid = pid;
 461         if (pgid < 0)
 462                 return -EINVAL;
 463         for_each_task(p) {
 464                 if (p->pid == pid)
 465                         goto found_task;
 466         }
 467         return -ESRCH;
 468 
 469 found_task:
 470         if (p->p_pptr == current || p->p_opptr == current) {
 471                 if (p->session != current->session)
 472                         return -EPERM;
 473                 if (p->did_exec)
 474                         return -EACCES;
 475         } else if (p != current)
 476                 return -ESRCH;
 477         if (p->leader)
 478                 return -EPERM;
 479         if (pgid != pid) {
 480                 struct task_struct * tmp;
 481                 for_each_task (tmp) {
 482                         if (tmp->pgrp == pgid &&
 483                          tmp->session == current->session)
 484                                 goto ok_pgid;
 485                 }
 486                 return -EPERM;
 487         }
 488 
 489 ok_pgid:
 490         p->pgrp = pgid;
 491         return 0;
 492 }
 493 
 494 asmlinkage int sys_getpgid(pid_t pid)
     /* [previous][next][first][last][top][bottom][index][help] */
 495 {
 496         struct task_struct * p;
 497 
 498         if (!pid)
 499                 return current->pgrp;
 500         for_each_task(p) {
 501                 if (p->pid == pid)
 502                         return p->pgrp;
 503         }
 504         return -ESRCH;
 505 }
 506 
 507 asmlinkage int sys_getpgrp(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 508 {
 509         return current->pgrp;
 510 }
 511 
 512 asmlinkage int sys_setsid(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 513 {
 514         if (current->leader)
 515                 return -EPERM;
 516         current->leader = 1;
 517         current->session = current->pgrp = current->pid;
 518         current->tty = NULL;
 519         current->tty_old_pgrp = 0;
 520         return current->pgrp;
 521 }
 522 
 523 /*
 524  * Supplementary group ID's
 525  */
 526 asmlinkage int sys_getgroups(int gidsetsize, gid_t *grouplist)
     /* [previous][next][first][last][top][bottom][index][help] */
 527 {
 528         int i;
 529         int * groups;
 530 
 531         if (gidsetsize) {
 532                 i = verify_area(VERIFY_WRITE, grouplist, sizeof(gid_t) * gidsetsize);
 533                 if (i)
 534                         return i;
 535         }
 536         groups = current->groups;
 537         for (i = 0 ; (i < NGROUPS) && (*groups != NOGROUP) ; i++, groups++) {
 538                 if (!gidsetsize)
 539                         continue;
 540                 if (i >= gidsetsize)
 541                         break;
 542                 put_user(*groups, grouplist);
 543                 grouplist++;
 544         }
 545         return(i);
 546 }
 547 
 548 asmlinkage int sys_setgroups(int gidsetsize, gid_t *grouplist)
     /* [previous][next][first][last][top][bottom][index][help] */
 549 {
 550         int     i;
 551 
 552         if (!suser())
 553                 return -EPERM;
 554         if (gidsetsize > NGROUPS)
 555                 return -EINVAL;
 556         for (i = 0; i < gidsetsize; i++, grouplist++) {
 557                 current->groups[i] = get_fs_word((unsigned short *) grouplist);
 558         }
 559         if (i < NGROUPS)
 560                 current->groups[i] = NOGROUP;
 561         return 0;
 562 }
 563 
 564 int in_group_p(gid_t grp)
     /* [previous][next][first][last][top][bottom][index][help] */
 565 {
 566         int     i;
 567 
 568         if (grp == current->fsgid)
 569                 return 1;
 570 
 571         for (i = 0; i < NGROUPS; i++) {
 572                 if (current->groups[i] == NOGROUP)
 573                         break;
 574                 if (current->groups[i] == grp)
 575                         return 1;
 576         }
 577         return 0;
 578 }
 579 
 580 asmlinkage int sys_newuname(struct new_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 581 {
 582         int error;
 583 
 584         if (!name)
 585                 return -EFAULT;
 586         error = verify_area(VERIFY_WRITE, name, sizeof *name);
 587         if (!error)
 588                 memcpy_tofs(name,&system_utsname,sizeof *name);
 589         return error;
 590 }
 591 
 592 asmlinkage int sys_uname(struct old_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 593 {
 594         int error;
 595         if (!name)
 596                 return -EFAULT;
 597         error = verify_area(VERIFY_WRITE, name,sizeof *name);
 598         if (error)
 599                 return error;
 600         memcpy_tofs(&name->sysname,&system_utsname.sysname,
 601                 sizeof (system_utsname.sysname));
 602         memcpy_tofs(&name->nodename,&system_utsname.nodename,
 603                 sizeof (system_utsname.nodename));
 604         memcpy_tofs(&name->release,&system_utsname.release,
 605                 sizeof (system_utsname.release));
 606         memcpy_tofs(&name->version,&system_utsname.version,
 607                 sizeof (system_utsname.version));
 608         memcpy_tofs(&name->machine,&system_utsname.machine,
 609                 sizeof (system_utsname.machine));
 610         return 0;
 611 }
 612 
 613 asmlinkage int sys_olduname(struct oldold_utsname * name)
     /* [previous][next][first][last][top][bottom][index][help] */
 614 {
 615         int error;
 616         if (!name)
 617                 return -EFAULT;
 618         error = verify_area(VERIFY_WRITE, name,sizeof *name);
 619         if (error)
 620                 return error;
 621         memcpy_tofs(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
 622         put_fs_byte(0,name->sysname+__OLD_UTS_LEN);
 623         memcpy_tofs(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
 624         put_fs_byte(0,name->nodename+__OLD_UTS_LEN);
 625         memcpy_tofs(&name->release,&system_utsname.release,__OLD_UTS_LEN);
 626         put_fs_byte(0,name->release+__OLD_UTS_LEN);
 627         memcpy_tofs(&name->version,&system_utsname.version,__OLD_UTS_LEN);
 628         put_fs_byte(0,name->version+__OLD_UTS_LEN);
 629         memcpy_tofs(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
 630         put_fs_byte(0,name->machine+__OLD_UTS_LEN);
 631         return 0;
 632 }
 633 
 634 asmlinkage int sys_sethostname(char *name, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 635 {
 636         int error;
 637 
 638         if (!suser())
 639                 return -EPERM;
 640         if (len < 0 || len > __NEW_UTS_LEN)
 641                 return -EINVAL;
 642         error = verify_area(VERIFY_READ, name, len);
 643         if (error)
 644                 return error;
 645         memcpy_fromfs(system_utsname.nodename, name, len);
 646         system_utsname.nodename[len] = 0;
 647         return 0;
 648 }
 649 
 650 asmlinkage int sys_gethostname(char *name, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 651 {
 652         int i;
 653 
 654         if (len < 0)
 655                 return -EINVAL;
 656         i = verify_area(VERIFY_WRITE, name, len);
 657         if (i)
 658                 return i;
 659         i = 1+strlen(system_utsname.nodename);
 660         if (i > len)
 661                 i = len;
 662         memcpy_tofs(name, system_utsname.nodename, i);
 663         return 0;
 664 }
 665 
 666 /*
 667  * Only setdomainname; getdomainname can be implemented by calling
 668  * uname()
 669  */
 670 asmlinkage int sys_setdomainname(char *name, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 671 {
 672         int     i;
 673         
 674         if (!suser())
 675                 return -EPERM;
 676         if (len > __NEW_UTS_LEN)
 677                 return -EINVAL;
 678         for (i=0; i < len; i++) {
 679                 if ((system_utsname.domainname[i] = get_fs_byte(name+i)) == 0)
 680                         return 0;
 681         }
 682         system_utsname.domainname[i] = 0;
 683         return 0;
 684 }
 685 
 686 asmlinkage int sys_getrlimit(unsigned int resource, struct rlimit *rlim)
     /* [previous][next][first][last][top][bottom][index][help] */
 687 {
 688         int error;
 689 
 690         if (resource >= RLIM_NLIMITS)
 691                 return -EINVAL;
 692         error = verify_area(VERIFY_WRITE,rlim,sizeof *rlim);
 693         if (error)
 694                 return error;
 695         memcpy_tofs(rlim, current->rlim + resource, sizeof(*rlim));
 696         return 0;       
 697 }
 698 
 699 asmlinkage int sys_setrlimit(unsigned int resource, struct rlimit *rlim)
     /* [previous][next][first][last][top][bottom][index][help] */
 700 {
 701         struct rlimit new_rlim, *old_rlim;
 702         int err;
 703 
 704         if (resource >= RLIM_NLIMITS)
 705                 return -EINVAL;
 706         err = verify_area(VERIFY_READ, rlim, sizeof(*rlim));
 707         if (err)
 708                 return err;
 709         memcpy_fromfs(&new_rlim, rlim, sizeof(*rlim));
 710         old_rlim = current->rlim + resource;
 711         if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
 712              (new_rlim.rlim_max > old_rlim->rlim_max)) &&
 713             !suser())
 714                 return -EPERM;
 715         if (resource == RLIMIT_NOFILE) {
 716                 if (new_rlim.rlim_cur > NR_OPEN || new_rlim.rlim_max > NR_OPEN)
 717                         return -EPERM;
 718         }
 719         *old_rlim = new_rlim;
 720         return 0;
 721 }
 722 
 723 /*
 724  * It would make sense to put struct rusage in the task_struct,
 725  * except that would make the task_struct be *really big*.  After
 726  * task_struct gets moved into malloc'ed memory, it would
 727  * make sense to do this.  It will make moving the rest of the information
 728  * a lot simpler!  (Which we're not doing right now because we're not
 729  * measuring them yet).
 730  */
 731 int getrusage(struct task_struct *p, int who, struct rusage *ru)
     /* [previous][next][first][last][top][bottom][index][help] */
 732 {
 733         int error;
 734         struct rusage r;
 735 
 736         error = verify_area(VERIFY_WRITE, ru, sizeof *ru);
 737         if (error)
 738                 return error;
 739         memset((char *) &r, 0, sizeof(r));
 740         switch (who) {
 741                 case RUSAGE_SELF:
 742                         r.ru_utime.tv_sec = CT_TO_SECS(p->utime);
 743                         r.ru_utime.tv_usec = CT_TO_USECS(p->utime);
 744                         r.ru_stime.tv_sec = CT_TO_SECS(p->stime);
 745                         r.ru_stime.tv_usec = CT_TO_USECS(p->stime);
 746                         r.ru_minflt = p->mm->min_flt;
 747                         r.ru_majflt = p->mm->maj_flt;
 748                         break;
 749                 case RUSAGE_CHILDREN:
 750                         r.ru_utime.tv_sec = CT_TO_SECS(p->cutime);
 751                         r.ru_utime.tv_usec = CT_TO_USECS(p->cutime);
 752                         r.ru_stime.tv_sec = CT_TO_SECS(p->cstime);
 753                         r.ru_stime.tv_usec = CT_TO_USECS(p->cstime);
 754                         r.ru_minflt = p->mm->cmin_flt;
 755                         r.ru_majflt = p->mm->cmaj_flt;
 756                         break;
 757                 default:
 758                         r.ru_utime.tv_sec = CT_TO_SECS(p->utime + p->cutime);
 759                         r.ru_utime.tv_usec = CT_TO_USECS(p->utime + p->cutime);
 760                         r.ru_stime.tv_sec = CT_TO_SECS(p->stime + p->cstime);
 761                         r.ru_stime.tv_usec = CT_TO_USECS(p->stime + p->cstime);
 762                         r.ru_minflt = p->mm->min_flt + p->mm->cmin_flt;
 763                         r.ru_majflt = p->mm->maj_flt + p->mm->cmaj_flt;
 764                         break;
 765         }
 766         memcpy_tofs(ru, &r, sizeof(r));
 767         return 0;
 768 }
 769 
 770 asmlinkage int sys_getrusage(int who, struct rusage *ru)
     /* [previous][next][first][last][top][bottom][index][help] */
 771 {
 772         if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
 773                 return -EINVAL;
 774         return getrusage(current, who, ru);
 775 }
 776 
 777 asmlinkage int sys_umask(int mask)
     /* [previous][next][first][last][top][bottom][index][help] */
 778 {
 779         int old = current->fs->umask;
 780 
 781         current->fs->umask = mask & S_IRWXUGO;
 782         return (old);
 783 }

/* [previous][next][first][last][top][bottom][index][help] */