/* 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 "SS5ExternalProgram.h"
S5RetCode S5AuthProgramCheck( struct _SS5AuthInfo *ai, pid_t pid )
{
char resp[3];
char prog[128];
char logString[128];
FILE *stream;
/*
* Build command line for program execution
*/
strncpy(prog,S5AuthCmd->ProgName,sizeof(S5AuthCmd->ProgName) - 1);
strncat(prog," ",sizeof(" "));
strncat(prog,ai->Username,sizeof(prog));
strncat(prog," ",sizeof(" "));
strncat(prog,ai->Password,sizeof(prog));
strncat(prog,"\0",sizeof("\0"));
/*
* Open pipe and fork
*/
if( (stream = popen(prog,"r")) == NULL ) {
ERRNO(pid)
return ERR;
}
/*
* Get standard output from generic external authentication program
*/
fscanf(stream,"%2s",resp);
if( pclose(stream) == -1 ) {
ERRNO(pid)
}
/*
* If standard output is equal to "OK" then authenticaton will be OK too
*/
if( STREQ(resp,"OK",sizeof("OK") - 1) )
return OK;
else
return ERR;
}
syntax highlighted by Code2HTML, v. 0.9.1