auth.c
Upload User: zibowangxu
Upload Date: 2007-01-04
Package Size: 331k
Code Size: 3k
Category:

Ftp Client

Development Platform:

Unix_Linux

  1. /****************************************************************************  
  2.  
  3.   Copyright (c) 1999 WU-FTPD Development Group.  
  4.   All rights reserved.
  5.   
  6.   Portions Copyright (c) 1980, 1985, 1988, 1989, 1990, 1991, 1993, 1994
  7.     The Regents of the University of California.
  8.   Portions Copyright (c) 1993, 1994 Washington University in Saint Louis.
  9.   Portions Copyright (c) 1996, 1998 Berkeley Software Design, Inc.
  10.   Portions Copyright (c) 1989 Massachusetts Institute of Technology.
  11.   Portions Copyright (c) 1998 Sendmail, Inc.
  12.   Portions Copyright (c) 1983, 1995, 1996, 1997 Eric P.  Allman.
  13.   Portions Copyright (c) 1997 by Stan Barber.
  14.   Portions Copyright (c) 1997 by Kent Landfield.
  15.   Portions Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997
  16.     Free Software Foundation, Inc.  
  17.  
  18.   Use and distribution of this software and its source code are governed 
  19.   by the terms and conditions of the WU-FTPD Software License ("LICENSE").
  20.  
  21.   If you did not receive a copy of the license, it may be obtained online
  22.   at http://www.wu-ftpd.org/license.html.
  23.  
  24.   $Id: auth.c,v 1.5 1999/08/24 23:41:38 wuftpd Exp $
  25.  
  26. ****************************************************************************/
  27. #include "config.h"
  28. #ifdef BSD_AUTH
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <setjmp.h>
  32. #include <sys/wait.h>
  33. #include <sys/param.h>
  34. #include <pwd.h>
  35. #include <signal.h>
  36. #include <stdlib.h>
  37. #include <syslog.h>
  38. #include <login_cap.h>
  39. int ext_auth = 0;
  40. login_cap_t *class = NULL;
  41. static char *challenge = NULL;
  42. char *start_auth(char *style, char *name, struct passwd *pwd)
  43. {
  44.     int s;
  45.     ext_auth = 1; /* authentication is always external */
  46.     if (challenge)
  47. free(challenge);
  48.     challenge = NULL;
  49.     if (!(class = login_getclass(pwd ? pwd->pw_class : 0)))
  50. return (NULL);
  51.     if (pwd && pwd->pw_passwd[0] == '')
  52. return (NULL);
  53.     if ((style = login_getstyle(class, style, "auth-ftp")) == NULL)
  54. return (NULL);
  55.     if (auth_check(name, class->lc_class, style, "challenge", &s) < 0)
  56. return (NULL);
  57.     if ((s & AUTH_CHALLENGE) == 0)
  58. return (NULL);
  59.     challenge = auth_value("challenge");
  60.     return (challenge);
  61. }
  62. char *check_auth(char *name, char *passwd)
  63. {
  64.     char *e;
  65.     int r;
  66.     if (ext_auth == 0)
  67. return ("Login incorrect.");
  68.     ext_auth = 0;
  69.     r = auth_response(name, class->lc_class, class->lc_style, "response",
  70.       NULL, challenge ? challenge : "", passwd);
  71.     if (challenge)
  72. free(challenge);
  73.     challenge = NULL;
  74.     if (r <= 0) {
  75. e = auth_value("errormsg");
  76. return (e ? e : "Login incorrect.");
  77.     }
  78.     if (!auth_approve(class, name, "ftp")) {
  79. syslog(LOG_INFO | LOG_AUTH,
  80.        "FTP LOGIN FAILED (HOST) as %s: approval failure.", name);
  81. return ("Approval failure.");
  82.     }
  83.     return (NULL);
  84. }
  85. #endif