home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / radius_2.zip / pcrypt.c < prev    next >
C/C++ Source or Header  |  1996-06-03  |  2KB  |  83 lines

  1. #include    <sys/types.h>
  2. #include    <sys/socket.h>
  3. #include    <sys/time.h>
  4. #include    <sys/file.h>
  5. #include    <netinet/in.h>
  6.  
  7. #include    <stdio.h>
  8. #include    <netdb.h>
  9. #include    <fcntl.h>
  10. #include    <pwd.h>
  11. #include    <time.h>
  12. #include    <ctype.h>
  13. #include    <unistd.h>
  14. #include    <signal.h>
  15. #include    <errno.h>
  16. #include   <process.h>
  17. #include    <sys/wait.h>
  18. #include    <io.h>
  19.  
  20. #if !defined(NOSHADOW)
  21. /*#include    <shadow.h>*/
  22. #endif /* !NOSHADOW */
  23.  
  24. #include    "radius.h"
  25.  
  26. int
  27. main(argc, argv)
  28. int    argc;
  29. char    **argv;
  30. {
  31.     struct    passwd    *pwd;
  32.     struct    passwd    *getpwnam();
  33.     char    *encpw;
  34.     char    *crypt();
  35.     char    *encrypted_pass;
  36.    char    *name;  
  37.    char    *passwd;
  38.  
  39.     name = argv[1];
  40.     passwd = argv[2];
  41.  
  42. #if !defined(NOSHADOW)
  43. #if defined(M_UNIX)
  44.     struct passwd    *spwd;
  45. #else
  46.     struct passwd    *spwd;
  47. #endif
  48. #endif /* !NOSHADOW */
  49.  
  50.     encpw = NULL;
  51.  
  52.     /* Get encrypted password from password file */
  53.     if((pwd = getpwnam(name)) == NULL) {
  54.         return(-1);
  55.     }
  56.  
  57.     encrypted_pass = pwd->pw_passwd;
  58.     fprintf(stderr,"Encpw1:%s",encrypted_pass);
  59.  
  60. #if !defined(NOSHADOW)
  61.     if(strcmp(pwd->pw_passwd, "x") == 0) {
  62. /*        if((spwd = getspnam(name)) == NULL) {
  63.             return(-1);
  64.         }
  65.         */
  66.       #if defined(M_UNIX)
  67.         encrypted_pass = spwd->pw_passwd;
  68. #else
  69.        encrypted_pass = spwd->pw_passwd;
  70. #endif    /* M_UNIX */
  71.     }
  72. #endif    /* !NOSHADOW */
  73.  
  74.     /* Run encryption algorythm */
  75.     encpw = crypt(passwd, encrypted_pass);
  76.     fprintf(stderr,"Encpw2:%s",encpw);
  77.     /* Check it */
  78.     if(strcmp(encpw, encrypted_pass)) {
  79.         return(-1);
  80.     }
  81.     return(0);
  82. }
  83.