home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Networking / wu-ftpd-2.4.2b13-MIHS / src / authenticate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-03  |  3.6 KB  |  121 lines

  1. /*
  2.  * Copyright (c) 1993, 1994  Washington University in Saint Louis All rights
  3.  * reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions are
  7.  * met: 1. Redistributions of source code must retain the above copyright
  8.  * notice, this list of conditions and the following disclaimer. 2.
  9.  * Redistributions in binary form must reproduce the above copyright notice,
  10.  * this list of conditions and the following disclaimer in the documentation
  11.  * and/or other materials provided with the distribution. 3. All advertising
  12.  * materials mentioning features or use of this software must display the
  13.  * following acknowledgement: This product includes software developed by the
  14.  * Washington University in Saint Louis and its contributors. 4. Neither the
  15.  * name of the University nor the names of its contributors may be used to
  16.  * endorse or promote products derived from this software without specific
  17.  * prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY WASHINGTON UNIVERSITY AND CONTRIBUTORS ``AS IS''
  20.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED.  IN NO EVENT SHALL WASHINGTON UNIVERSITY OR CONTRIBUTORS
  23.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29.  * POSSIBILITY OF SUCH DAMAGE.
  30.  */
  31. #ifndef lint
  32. static char rcsid[] = "@(#)$Id: authenticate.c,v 1.4 1997/03/03 09:39:42 sob Exp sob $";
  33. #endif /* not lint */
  34. #include "config.h"
  35.  
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include "support/authuser.h"
  39. #include "authenticate.h"
  40.  
  41. #if USE_A_RFC931
  42. #include <signal.h>
  43. #include <setjmp.h>
  44.  
  45. #define RFC931_Timeout 10
  46. static jmp_buf  timebuf;
  47.  
  48. #endif                /* USE_A_RFC931 */
  49.  
  50.  
  51. #define AUTHNAMESIZE 100
  52.  
  53. char authuser[AUTHNAMESIZE];
  54. int authenticated;
  55.  
  56. #if USE_A_RFC931
  57. static          void
  58. timout (sig)
  59.     int             sig;
  60. {
  61.     longjmp (timebuf, sig);
  62. }
  63.  
  64. #endif                /* USE_A_RFC931 */
  65. /*
  66.  * This routine actually returns nothing. It just sets the authenticated global
  67.  * variable.
  68.  */
  69. int
  70. authenticate()
  71. {
  72.  
  73. #if USE_A_RFC931
  74.     unsigned long in;
  75.     unsigned short  local,
  76.                     remote;
  77.  
  78. #endif /* USE_A_RFC931 */
  79.     char *user;
  80.  
  81.  /*
  82.   * Ideally more authentication schemes would be called from here, with the
  83.   * strongest called first.  One possible double-check would be to verify that
  84.   * the results of all authentication calls (returning identical data!) are
  85.   * checked against each other.
  86.   */
  87.  
  88.     authenticated = 0;          /* this is a bitmask, one bit per method */
  89.  
  90.     user = "*";
  91.  
  92. #if USE_A_RFC931
  93.  
  94.  /*
  95.   * Set up a timer so we won't get stuck while waiting for the server.
  96.   */
  97.  
  98.     signal (SIGALRM, timout);
  99.  
  100.     if (auth_fd(0, &in, &local, &remote) == -1)
  101.         user = "?";             /* getpeername/getsockname failure */
  102.     else
  103.     {
  104.     alarm (RFC931_Timeout);
  105.     if (setjmp (timebuf) != 0 || !(user = auth_tcpuser (in, local, remote)))
  106.     {
  107.             user = "*";         /* remote host doesn't support RFC 931 */
  108.     }
  109.     else
  110.     {
  111.             authenticated |= A_RFC931;
  112.         }
  113.     alarm (0);
  114.     }
  115. #endif /* USE_A_RFC931 */
  116.  
  117.     strncpy(authuser, user, sizeof(authuser));
  118.     authuser[AUTHNAMESIZE - 1] = '\0';
  119.     return(0);
  120. }
  121.