[comp.os.minix] su with /usr/adm/sulog

jac@dobag.in-berlin.de (Joerg Conradt) (04/06/91)

hello world,
as the minix-su command doesn't record who used it and when, i added
a procedure which makes the su like the su in SYS V, Rel 3.

You have to add these includes:
#include <stdio.h>
#include <time.h>

and (after the includes, in front of main) to define the file,
the record is written to:
#define SULOG "/usr/adm/sulog"

After this there's the usual main-prg!

In front of the line :   " std_err("Sorry\n"); " you insert:
		sulist(0);

And in front of the setgid(...) and setuid(...) you insert the following
two lines:
  sulog(1);
  pwd = getpwnam(name);

That's all you have to change in the programm.
You have to add the follwing procedure at the end of the file and
the su command will record all SUs. Of course only root is allowed to
see or to modify the SULOG-file!!!
Dont forget to exec "chmod 4755 su" and "chown root su" after compiling
the new su, else it won't work, of course!
Much fun with this su - and worse hacking!
Joerg Conradt

--- CUT HERE!! ---

sulist(worked)			/* Added by Joerg Conradt, Berlin, Germany */
int worked;			/* on the 4th April 1991		   */
{				/* UUCP: jac@dobag.in-berlin.de 	   */
  register char *name;
  FILE *sudat;
  char *writein,*malloc();
  struct passwd *getpwuid();
  struct tm *ptr;
  time_t lt;

  writein = (char *) malloc(80);
 
  lt = time(NULL);
  ptr = localtime(&lt);
  
  strcpy (writein,"SU ");
  strncat (writein,asctime(ptr),strlen(asctime(ptr))-1);     /* no /n */

  if (worked == 0) { strcat (writein," - "); }
  else		   { strcat (writein," + "); }

  strcat (writein,ctermid());
  strcat (writein," ");
  strcat (writein,*getpwuid(getuid()));
  strcat (writein,"-");
  strcat (writein,name);
  strcat (writein,"\n");

  if ( (sudat=fopen(SULOG,"a")) == 0) {		/* append sulog   */
	std_err("su: Can't open sulog-file (fatal)\n");
	exit (4); }
  if ( fputs(writein,sudat) == EOF ) {
	std_err("su: Can't write to sulog-file (fatal)\n");
	exit (4); }
  fclose(sudat);
  chown(SULOG,0,0);
  chmod(SULOG,0600);
}

--- END ---

-- 
UUCP: jac@dobag.in-berlin.de  | - The number of viewers watching you is
Alias Joerg Conradt           |   proportional to the stupidity of your
1000 Berlin 41 Germany        |   action.
++ 0307958397                 | - "Murphy was an optimist"