/* *Needacompletetypeforstructauth_info,eventhoughwe're
* not really using it if this module (UNIX authentication) is selected */ struct auth_info
{ char dummy;
};
/* Need a non-NULL pointer to return to indicate success */ staticstruct auth_info success = {0};
/* Most likely codepath return from here is 'not authenticated' */ enum scp_login_status status = E_SCP_LOGIN_NOT_AUTHENTICATED;
/* Find the encrypted password */ if ((spw = getpwnam(user)) != NULL)
{ if (g_strncmp(spw->pw_passwd, "x", 3) == 0)
{ struct spwd *stp;
/* the system is using shadow */ if ((stp = getspnam(user)) == NULL)
{
LOG(LOG_LEVEL_ERROR, "Can't get shadow entry for account %s",
user);
status = E_SCP_LOGIN_GENERAL_ERROR;
} else
{ if (1 == auth_account_disabled(stp))
{
LOG(LOG_LEVEL_INFO, "account %s is disabled", user);
status = E_SCP_LOGIN_NOT_AUTHORIZED;
} else
{
encr = stp->sp_pwdp;
}
}
} else
{ /* old system with only passwd */
encr = spw->pw_passwd;
}
}
if (encr != NULL)
{ constchar *epass; if ((epass = crypt(pass, encr)) != NULL &&
g_strcmp(encr, epass) == 0)
{
status = E_SCP_LOGIN_OK;
}
}
/* Need a non-NULL pointer to return to indicate success */ staticstruct auth_info success = {0};
enum scp_login_status status = E_SCP_LOGIN_OK;
/* Try to check for a disabled account */ if ((spw = getpwnam(user)) != NULL)
{ if (g_strncmp(spw->pw_passwd, "x", 3) == 0)
{ struct spwd *stp;
/* the system is using shadow */ if ((stp = getspnam(user)) == NULL)
{
LOG(LOG_LEVEL_ERROR, "Can't get shadow entry for account %s",
user);
status = E_SCP_LOGIN_GENERAL_ERROR;
} else
{ if (1 == auth_account_disabled(stp))
{
LOG(LOG_LEVEL_INFO, "account %s is disabled", user);
status = E_SCP_LOGIN_NOT_AUTHORIZED;
}
}
}
}
/******************************************************************************/ /* returns error */ int
auth_start_session(struct auth_info *auth_info, int display_num)
{ return0;
}
/******************************************************************************/ int
auth_end(struct auth_info *auth_info)
{ return0;
}
/******************************************************************************/ int
auth_set_env(struct auth_info *auth_info)
{ return0;
}
/******************************************************************************/ int
auth_check_pwd_chg(constchar *user)
{ struct passwd *spw; struct spwd *stp; int now; long today;
spw = getpwnam(user);
if (spw == 0)
{ return AUTH_PWD_CHG_ERROR;
}
if (g_strncmp(spw->pw_passwd, "x", 3) != 0)
{ /* old system with only passwd */ return AUTH_PWD_CHG_OK;
}
/* the system is using shadow */
stp = getspnam(user);
if (stp == 0)
{ return AUTH_PWD_CHG_ERROR;
}
/* check if we need a pwd change */
now = g_time1();
today = now / SECS_PER_DAY;
if (stp->sp_expire == -1)
{ return AUTH_PWD_CHG_OK;
}
if (today >= (stp->sp_lstchg + stp->sp_max))
{ return AUTH_PWD_CHG_CHANGE_MANDATORY;
}
if (today < ((stp->sp_lstchg) + (stp->sp_min)))
{ /* cannot change pwd for now */ return AUTH_PWD_CHG_NOT_NOW;
}
return AUTH_PWD_CHG_OK;
}
int
auth_change_pwd(constchar *user, constchar *newpwd)
{ struct passwd *spw; struct spwd *stp; char hash[35] = ""; long today;
FILE *fd;
if (0 != lckpwdf())
{ return1;
}
/* open passwd */
spw = getpwnam(user);
if (spw == 0)
{ return1;
}
if (g_strncmp(spw->pw_passwd, "x", 3) != 0)
{ /* old system with only passwd */ if (auth_crypt_pwd(spw->pw_passwd, newpwd, hash) != 0)
{
ulckpwdf(); return1;
}
spw->pw_passwd = g_strdup(hash);
fd = fopen("/etc/passwd", "rw");
putpwent(spw, fd);
} else
{ /* the system is using shadow */
stp = getspnam(user);
if (stp == 0)
{ return1;
}
/* old system with only passwd */ if (auth_crypt_pwd(stp->sp_pwdp, newpwd, hash) != 0)
{
ulckpwdf(); return1;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.