/* Socks Server 5
 * Copyright (C) 2002 - 2006 by Matteo Ricchetti - <matteo.ricchetti@libero.it>

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */


#include "SS5Main.h"
#include "SS5Mod_authentication.h"
#include "SS5Basic.h"


S5RetCode S5PwdFileOpen( pid_t pid )
{
  char logString[128];

  if( (S5PwdFile = fopen(S5PasswordFile,"r")) == NULL ) {
    ERRNO(pid)
    return ERR;
  }
  return OK;
}


S5RetCode S5PwdFileCheck( struct _SS5AuthInfo *ai )
{
  char user[64];
  char password[64];

  /* 
   *    Look for username and password into password file 
   */
  while( fscanf(S5PwdFile,"%63s %63s",user,password) != EOF ) {
    if( STRCASEEQ(ai->Username,user,sizeof(user) - 1) && 
        STREQ(ai->Password,password,sizeof(password) - 1) )
      return OK;
  }
  return ERR;
}


S5RetCode S5PwdFileClose( pid_t pid )
{
  char logString[128];

  if( fclose(S5PwdFile) ) {
    ERRNO(pid)
    return ERR;
  }
  return OK;
}



syntax highlighted by Code2HTML, v. 0.9.1