home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / kernel-s / v1.1 / acct_for.1 next >
Text File  |  1995-10-10  |  9KB  |  284 lines

  1. diff -ru --new-file linux-1.1.48/fs/exec.c linux/fs/exec.c
  2. --- linux-1.1.48/fs/exec.c    Mon Aug 29 14:42:39 1994
  3. +++ linux/fs/exec.c    Mon Aug 29 14:34:45 1994
  4. @@ -203,6 +203,7 @@
  5.      if (!file.f_op->write)
  6.          goto close_coredump;
  7.      has_dumped = 1;
  8. +    current->flags |= PF_DUMPCORE;
  9.  /* changed the size calculations - should hopefully work better. lbt */
  10.      dump.magic = CMAGIC;
  11.      dump.start_code = 0;
  12. @@ -817,6 +818,7 @@
  13.      current->mm->mmap = NULL;
  14.      current->suid = current->euid = current->fsuid = bprm->e_uid;
  15.      current->sgid = current->egid = current->fsgid = bprm->e_gid;
  16. +     current->flags &= ~PF_FORKNOEXEC;
  17.      if (N_MAGIC(ex) == OMAGIC) {
  18.          do_mmap(NULL, 0, ex.a_text+ex.a_data,
  19.              PROT_READ|PROT_WRITE|PROT_EXEC,
  20. diff -ru --new-file linux-1.1.48/include/linux/acct.h linux/include/linux/acct.h
  21. --- linux-1.1.48/include/linux/acct.h    Thu Jan  1 02:00:00 1970
  22. +++ linux/include/linux/acct.h    Mon Aug 29 14:33:03 1994
  23. @@ -0,0 +1,29 @@
  24. +#ifndef __LINUX_ACCT_H
  25. +#define __LINUX_ACCT_H
  26. +
  27. +#define ACCT_COMM 16
  28. +
  29. +struct acct
  30. +{
  31. +    char    ac_comm[ACCT_COMM];    /* Accounting command name */
  32. +    time_t    ac_utime;        /* Accounting user time */
  33. +    time_t    ac_stime;        /* Accounting system time */
  34. +    time_t    ac_etime;        /* Accounting elapsed time */
  35. +    time_t    ac_btime;        /* Beginning time */
  36. +    uid_t    ac_uid;            /* Accounting user ID */
  37. +    gid_t    ac_gid;            /* Accounting group ID */
  38. +    dev_t    ac_tty;            /* controlling tty */
  39. +    char    ac_flag;        /* Accounting flag */
  40. +    long    ac_minflt;        /* Accounting minor pagefaults */
  41. +    long    ac_majflt;        /* Accounting major pagefaults */
  42. +    long    ac_exitcode;        /* Accounting process exitcode */
  43. +};
  44. +
  45. +#define AFORK    0001    /* has executed fork, but no exec */
  46. +#define ASU    0002    /* used super-user privileges */
  47. +#define ACORE    0004    /* dumped core */
  48. +#define AXSIG    0010    /* killed by a signal */
  49. +
  50. +#define AHZ     100
  51. +
  52. +#endif
  53. diff -ru --new-file linux-1.1.48/include/linux/kernel.h linux/include/linux/kernel.h
  54. --- linux-1.1.48/include/linux/kernel.h    Thu Aug 11 17:00:17 1994
  55. +++ linux/include/linux/kernel.h    Mon Aug 29 14:38:16 1994
  56. @@ -55,16 +55,9 @@
  57.      __attribute__ ((format (printf, 1, 2)));
  58.  
  59.  /*
  60. - * This is defined as a macro, but at some point this might become a
  61. - * real subroutine that sets a flag if it returns true (to do
  62. - * BSD-style accounting where the process is flagged if it uses root
  63. - * privs).  The implication of this is that you should do normal
  64. - * permissions checks first, and check suser() last.
  65. - *
  66.   * "suser()" checks against the effective user id, while "fsuser()"
  67.   * is used for file permission checking and checks against the fsuid..
  68.   */
  69. -#define suser() (current->euid == 0)
  70.  #define fsuser() (current->fsuid == 0)
  71.  
  72.  extern int splx (int new_ipl);
  73. diff -ru --new-file linux-1.1.48/include/linux/sched.h linux/include/linux/sched.h
  74. --- linux-1.1.48/include/linux/sched.h    Mon Aug 29 14:42:44 1994
  75. +++ linux/include/linux/sched.h    Mon Aug 29 14:33:12 1994
  76. @@ -310,6 +310,10 @@
  77.                      /* Not implemented yet, only for 486*/
  78.  #define PF_PTRACED    0x00000010    /* set if ptrace (0) has been called. */
  79.  #define PF_TRACESYS    0x00000020    /* tracing system calls */
  80. +#define PF_FORKNOEXEC    0x00000040    /* forked but didn't exec */
  81. +#define PF_SUPERPREV    0x00000100    /* used super-user privileges */
  82. +#define PF_DUMPCORE    0x00000200    /* dumped core */
  83. +#define PF_SIGNALED    0x00000400    /* killed by a signal */
  84.  
  85.  /*
  86.   * cloning flags:
  87. @@ -449,6 +453,19 @@
  88.  
  89.  #define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
  90.  #define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
  91. +
  92. +/*
  93. + * This has now become a routine instead of a macro, it sets a flag if
  94. + * it returns true (to do BSD-style accounting where the process is flagged
  95. + * if it uses root privs). The implication of this is that you should do
  96. + * normal permissions checks first, and check suser() last.
  97. + */
  98. +extern inline int suser(void)
  99. +{
  100. +    if (current->euid == 0)
  101. +        current->flags |= PF_SUPERPREV;
  102. +    return (current->euid == 0);
  103. +}
  104.  
  105.  /*
  106.   * The wait-queues are circular lists, and you have to be *very* sure
  107. diff -ru --new-file linux-1.1.48/kernel/exit.c linux/kernel/exit.c
  108. --- linux-1.1.48/kernel/exit.c    Tue Aug  9 09:34:45 1994
  109. +++ linux/kernel/exit.c    Mon Aug 29 14:33:13 1994
  110. @@ -19,6 +19,7 @@
  111.  #include <asm/segment.h>
  112.  extern void shm_exit (void);
  113.  extern void sem_exit (void);
  114. +extern void acct_process (long exitcode);
  115.  
  116.  int getrusage(struct task_struct *, int, struct rusage *);
  117.  
  118. @@ -411,6 +412,7 @@
  119.          intr_count = 0;
  120.      }
  121.  fake_volatile:
  122. +    acct_process(code);
  123.      if (current->semun)
  124.          sem_exit();
  125.      if (current->shm)
  126. diff -ru --new-file linux-1.1.48/kernel/fork.c linux/kernel/fork.c
  127. --- linux-1.1.48/kernel/fork.c    Tue Jul 26 11:25:11 1994
  128. +++ linux/kernel/fork.c    Mon Aug 29 14:33:13 1994
  129. @@ -188,7 +188,8 @@
  130.      p->did_exec = 0;
  131.      p->kernel_stack_page = 0;
  132.      p->state = TASK_UNINTERRUPTIBLE;
  133. -    p->flags &= ~(PF_PTRACED|PF_TRACESYS);
  134. +    p->flags &= ~(PF_PTRACED|PF_TRACESYS|PF_SUPERPREV);
  135. +    p->flags |= PF_FORKNOEXEC;
  136.      p->pid = last_pid;
  137.      p->p_pptr = p->p_opptr = current;
  138.      p->p_cptr = NULL;
  139. diff -ru --new-file linux-1.1.48/kernel/signal.c linux/kernel/signal.c
  140. --- linux-1.1.48/kernel/signal.c    Fri Jun 17 15:36:19 1994
  141. +++ linux/kernel/signal.c    Mon Aug 29 14:33:13 1994
  142. @@ -356,6 +356,7 @@
  143.                  /* fall through */
  144.              default:
  145.                  current->signal |= _S(signr & 0x7f);
  146. +                current->flags |= PF_SIGNALED;
  147.                  do_exit(signr);
  148.              }
  149.          }
  150. diff -ru --new-file linux-1.1.48/kernel/sys.c linux/kernel/sys.c
  151. --- linux-1.1.48/kernel/sys.c    Mon Aug 29 14:42:46 1994
  152. +++ linux/kernel/sys.c    Mon Aug 29 14:33:14 1994
  153. @@ -17,7 +17,11 @@
  154.  #include <linux/ptrace.h>
  155.  #include <linux/stat.h>
  156.  #include <linux/mman.h>
  157. -
  158. +#include <linux/fcntl.h>
  159. +#include <linux/acct.h>
  160. +#include <linux/tty.h>
  161. +#include <sys/sysmacros.h>
  162. +  
  163.  #include <asm/segment.h>
  164.  #include <asm/io.h>
  165.  
  166. @@ -250,10 +254,113 @@
  167.          return -EPERM;
  168.      return 0;
  169.  }
  170. -
  171. -asmlinkage int sys_acct(void)
  172. -{
  173. -    return -ENOSYS;
  174. +  
  175. +static char acct_active = 0;
  176. +static struct file acct_file;
  177. +
  178. +int acct_process(long exitcode)
  179. +{
  180. +   struct acct ac;
  181. +   unsigned short fs;
  182. +
  183. +   if (acct_active) {
  184. +      strncpy(ac.ac_comm, current->comm, ACCT_COMM);
  185. +      ac.ac_comm[ACCT_COMM] = '\0';
  186. +      ac.ac_utime = current->utime;
  187. +      ac.ac_stime = current->stime;
  188. +      ac.ac_btime = CT_TO_SECS(current->start_time) + (xtime.tv_sec - (jiffies / HZ));
  189. +      ac.ac_etime = CURRENT_TIME - ac.ac_btime;
  190. +      ac.ac_uid   = current->uid;
  191. +      ac.ac_gid   = current->gid;
  192. +      ac.ac_tty   = (current)->tty == NULL ? -1 : 
  193. +         makedev (4, current->tty->device);
  194. +      ac.ac_flag  = 0;
  195. +      if (current->flags & PF_FORKNOEXEC)
  196. +         ac.ac_flag |= AFORK;
  197. +      if (current->flags & PF_SUPERPREV)
  198. +         ac.ac_flag |= ASU;
  199. +      if (current->flags & PF_DUMPCORE)
  200. +         ac.ac_flag |= ACORE;
  201. +      if (current->flags & PF_SIGNALED)
  202. +         ac.ac_flag |= AXSIG;
  203. +      ac.ac_minflt = current->mm->min_flt;
  204. +      ac.ac_majflt = current->mm->maj_flt;
  205. +      ac.ac_exitcode = exitcode;
  206. +
  207. +      /* Kernel segment override */
  208. +      fs = get_fs();
  209. +      set_fs(KERNEL_DS);
  210. +
  211. +      acct_file.f_op->write(acct_file.f_inode, &acct_file,
  212. +                             (char *)&ac, sizeof(struct acct));
  213. +
  214. +      set_fs(fs);
  215. +   }
  216. +   return 0;
  217. +}
  218. +
  219. +asmlinkage int sys_acct(const char *name)
  220. +{
  221. +   struct inode *inode = (struct inode *)0;
  222. +   char *tmp;
  223. +   int error;
  224. +
  225. +   if (!suser())
  226. +      return -EPERM;
  227. +
  228. +   if (name == (char *)0) {
  229. +      if (acct_active) {
  230. +         if (acct_file.f_op->release)
  231. +            acct_file.f_op->release(acct_file.f_inode, &acct_file);
  232. +
  233. +         if (acct_file.f_inode != (struct inode *) 0)
  234. +            iput(acct_file.f_inode);
  235. +
  236. +         acct_active = 0;
  237. +      }
  238. +      return 0;
  239. +   } else {
  240. +      if (!acct_active) {
  241. +
  242. +         if ((error = getname(name, &tmp)) != 0)
  243. +            return (error);
  244. +
  245. +         error = open_namei(tmp, O_RDWR, 0600, &inode, 0);
  246. +         putname(tmp);
  247. +
  248. +         if (error)
  249. +            return (error);
  250. +
  251. +         if (!S_ISREG(inode->i_mode)) {
  252. +            iput(inode);
  253. +            return -EACCES;
  254. +         }
  255. +
  256. +         if (!inode->i_op || !inode->i_op->default_file_ops || 
  257. +             !inode->i_op->default_file_ops->write) {
  258. +            iput(inode);
  259. +            return -EIO;
  260. +         }
  261. +
  262. +         acct_file.f_mode = 3;
  263. +         acct_file.f_flags = 0;
  264. +         acct_file.f_count = 1;
  265. +         acct_file.f_inode = inode;
  266. +         acct_file.f_pos = inode->i_size;
  267. +         acct_file.f_reada = 0;
  268. +         acct_file.f_op = inode->i_op->default_file_ops;
  269. +
  270. +         if (acct_file.f_op->open)
  271. +            if (acct_file.f_op->open(acct_file.f_inode, &acct_file)) {
  272. +               iput(inode);
  273. +               return -EIO;
  274. +            }
  275. +
  276. +         acct_active = 1;
  277. +         return 0;
  278. +      } else
  279. +         return -EBUSY;
  280. +   }
  281.  }
  282.  
  283.  asmlinkage int sys_phys(void)
  284.