Fix password authentication to handle different encryption algorithms

ulab-next
Guan-Zhong Huang 12 years ago
parent 6fd7deb510
commit b518a3bfe9

@ -50,12 +50,9 @@ auth_account_disabled(struct spwd *stp);
long DEFAULT_CC long DEFAULT_CC
auth_userpass(char *user, char *pass, int *errorcode) auth_userpass(char *user, char *pass, int *errorcode)
{ {
char salt[13] = "$1$"; const char *encr;
char hash[35] = "";
char *encr = 0;
struct passwd *spw; struct passwd *spw;
struct spwd *stp; struct spwd *stp;
int saltcnt = 0;
spw = getpwnam(user); spw = getpwnam(user);
@ -80,46 +77,15 @@ auth_userpass(char *user, char *pass, int *errorcode)
return 0; return 0;
} }
g_strncpy(hash, stp->sp_pwdp, 34); encr = stp->sp_pwdp;
} }
else else
{ {
/* old system with only passwd */ /* old system with only passwd */
g_strncpy(hash, spw->pw_passwd, 34); encr = spw->pw_passwd;
}
hash[34] = '\0';
if (g_strncmp(hash, "$1$", 3) == 0)
{
/* 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);
if (g_strncmp(encr, hash, 34) != 0)
{
return 0;
} }
return 1; return (strcmp(encr, crypt(pass, encr)) == 0);
} }
/******************************************************************************/ /******************************************************************************/

Loading…
Cancel
Save