home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume15 / sec / part01 / sec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-14  |  1.3 KB  |  88 lines

  1. /*
  2.  *
  3.  * sec.c
  4.  *
  5.  * Grudgingly give out root shells to authorized users.
  6.  *
  7.  * Usage: sec
  8.  *
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <syslog.h>
  13. #include <strings.h>
  14. #include "config.h"
  15.  
  16. int getline(file,s)
  17. FILE *file;
  18. char *s;
  19. {
  20.   while (((*s=getc(file))!=EOF) && (*s!='\n')) s++;
  21.   if ((*s)==EOF) return 0;
  22.   *s=0;
  23.   return 1;
  24. }
  25.  
  26. extern char *crypt();
  27.  
  28. char ckpw(b)
  29. char *b;
  30. {
  31.   char *a,*encr,input[10];
  32.   int f;
  33.  
  34.   if (!strlen(b))
  35.   {
  36.     printf("Null PW. Please use 'secpw' and add one.\n");
  37.     return 1;
  38.   }
  39.   strcpy(input,getpass("Password:"));
  40.   encr=crypt(input,b);
  41.   return(!strcmp(encr,b));
  42. }
  43.  
  44. main()
  45. {
  46.   FILE* f;
  47.   char str[80],ok=0;
  48.  
  49.   f=fopen(FILENAME,"r");
  50.   if (f!=NULL)
  51.   {
  52.     while(getline(f,str))
  53.     {
  54.       char b[16],*c;
  55.       c=index(str,':');
  56.       if (c==NULL) continue;
  57.       strcpy(b,c+1);
  58.       *c='\0';
  59.       if (!strcmp(str,getlogin()))
  60.         if (ckpw(b))
  61.           ok=1;
  62.     }
  63.     fclose(f);
  64.   }
  65.   else
  66.   {
  67.     printf("Error reading file.\n");
  68.     exit(1);
  69.   }
  70.  
  71.   openlog("sec",0,LOG_FACILITY);
  72.  
  73.   if (ok)
  74.   {
  75.     syslog(LOG_OK_PRI,"security access: %s",getlogin());
  76.     seteuid(0);
  77.     setegid(0);
  78.     setuid(0);
  79.     setgid(0);
  80.     execl("/bin/csh"," SEC",(char*)0);
  81.   }
  82.   else
  83.   {
  84.     syslog(LOG_FAIL_PRI,"security access DENIED: %s",getlogin());
  85.     printf("Not Authorized.\n");
  86.   }
  87. }
  88.