xrdp/sesman/verify_user.c

121 lines
2.6 KiB
C
Raw Normal View History

2005-06-05 03:51:51 +04:00
/*
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., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005-2006
2005-06-05 03:51:51 +04:00
*/
2006-05-26 00:34:32 +04:00
/**
*
* @file verify_user.c
* @brief Authenticate user using standard unix passwd/shadow system
* @author Jay Sorg
*
*/
2005-12-15 23:41:03 +03:00
#include "sesman.h"
2005-06-05 03:51:51 +04:00
#define _XOPEN_SOURCE
2006-05-31 21:47:43 +04:00
#include <stdio.h>
2005-12-15 23:41:03 +03:00
#include <sys/types.h>
#include <crypt.h>
2005-06-05 03:51:51 +04:00
#include <shadow.h>
#include <pwd.h>
2005-12-15 23:41:03 +03:00
extern struct config_sesman g_cfg;
2005-06-05 03:51:51 +04:00
/******************************************************************************/
/* returns boolean */
2005-12-15 23:41:03 +03:00
long DEFAULT_CC
2005-07-07 07:08:03 +04:00
auth_userpass(char* user, char* pass)
2005-06-05 03:51:51 +04:00
{
char salt[13] = "$1$";
char hash[35] = "";
char* encr = 0;
struct passwd* spw;
struct spwd* stp;
int saltcnt = 0;
spw = getpwnam(user);
if (spw == 0)
{
return 0;
}
2005-12-15 23:41:03 +03:00
if (g_strncmp(spw->pw_passwd, "x", 3) == 0)
2005-06-05 03:51:51 +04:00
{
/* the system is using shadow */
stp = getspnam(user);
if (stp == 0)
{
return 0;
}
2005-12-15 23:41:03 +03:00
g_strncpy(hash, stp->sp_pwdp, 34);
2005-06-05 03:51:51 +04:00
}
else
{
/* old system with only passwd */
2005-12-15 23:41:03 +03:00
g_strncpy(hash, spw->pw_passwd, 34);
2005-06-05 03:51:51 +04:00
}
hash[34] = '\0';
2005-12-15 23:41:03 +03:00
if (g_strncmp(hash, "$1$", 3) == 0)
2005-06-05 03:51:51 +04:00
{
/* gnu style crypt(); */
saltcnt = 3;
while ((hash[saltcnt] != '$') && (saltcnt < 11))
{
salt[saltcnt] = hash[saltcnt];
saltcnt++;
}
salt[saltcnt] = '$';
salt[saltcnt + 1] = '\0';
}
else
{
/* classic two char salt */
salt[0] = hash[0];
salt[1] = hash[1];
salt[2] = '\0';
}
encr = crypt(pass,salt);
2005-12-15 23:41:03 +03:00
if (g_strncmp(encr, hash, 34) != 0)
2005-06-05 03:51:51 +04:00
{
return 0;
}
return 1;
}
2005-07-19 06:22:33 +04:00
/******************************************************************************/
/* returns error */
int DEFAULT_CC
2005-12-15 23:41:03 +03:00
auth_start_session(long in_val, int in_display)
2005-07-19 06:22:33 +04:00
{
return 0;
}
/******************************************************************************/
int DEFAULT_CC
2005-12-15 23:41:03 +03:00
auth_end(long in_val)
2005-07-19 06:22:33 +04:00
{
return 0;
}
2005-08-14 06:22:11 +04:00
/******************************************************************************/
int DEFAULT_CC
2005-12-15 23:41:03 +03:00
auth_set_env(long in_val)
2005-08-14 06:22:11 +04:00
{
return 0;
}
2005-12-15 23:41:03 +03:00