/* Added by Ondrej Jombik */ #include #include #include #include #include "../main.h" #include "error.h" #include "pathexec.h" #include "prot.h" #ifndef SYSLOG_LEVEL # error SYSLOG_LEVEL not defined #else # if SYSLOG_LEVEL >= 1 # include # endif #endif extern char *crypt(); #include static struct passwd *pw; #include "hasspnam.h" #undef HASGETSPNAM /* Nepto hack */ #ifdef HASGETSPNAM # include static struct spwd *spw; #endif #include "hasuserpw.h" #ifdef HASUSERPW # include static struct userpw *upw; #endif extern char *login; extern char *password; extern char remotehost[BUFLEN]; extern char remoteip[BUFLEN]; extern char remoteinfo[BUFLEN]; int main_sys(int argc, char **argv) { char *encrypted; char *stored; /* Here we have global variables: 1. login 2. password */ pw = getpwnam(login); if (pw) stored = pw->pw_passwd; else { if (errno == error_txtbsy) exit(111); #if SYSLOG_LEVEL >= 5 /* Value of 5 is used, because this message will appear on every virtual user logon. */ syslog(SYSLOG_INFO, "sys: FAILED: unknown username: %s", login); #endif return -1; } #ifdef HASUSERPW upw = getuserpw(login); if (upw) stored = upw->upw_passwd; else if (errno == error_txtbsy) exit(111); #endif #ifdef HASGETSPNAM spw = getspnam(login); if (spw) stored = spw->sp_pwdp; else if (errno == error_txtbsy) exit(111); #endif if (!stored) exit(1); encrypted = crypt(password, stored); #if SYSLOG_LEVEL >= 9 syslog(SYSLOG_DEBUG, "sys: debug: login = %s", login); syslog(SYSLOG_DEBUG, "sys: debug: password = %s", password); syslog(SYSLOG_DEBUG, "sys: debug: stored = %s", stored); syslog(SYSLOG_DEBUG, "sys: debug: encrypted = %s", encrypted); #endif /* Here are password compared. */ if (! *stored || strcmp(encrypted, stored)) { #if SYSLOG_LEVEL >= 3 syslog(SYSLOG_INFO, "sys: FAILED: %s [%s] - password incorrect (%s)" " from %s@%s [%s]", login, pw->pw_name, password, remoteinfo, remotehost, remoteip); #endif return -1; } nuke_dynamic_string(&login); nuke_dynamic_string(&password); if (prot_gid((int) pw->pw_gid) == -1) { #if SYSLOG_LEVEL >= 3 syslog(SYSLOG_INFO, "sys: FAILED: %s - protected GID: %d", pw->pw_name, (int) pw->pw_gid); #endif exit(1); } if (prot_uid((int) pw->pw_uid) == -1) { #if SYSLOG_LEVEL >= 3 syslog(SYSLOG_INFO, "sys: FAILED: %s - protected UID: %d", pw->pw_name, (int) pw->pw_uid); #endif exit(1); } if (chdir(pw->pw_dir) == -1) { #if SYSLOG_LEVEL >= 3 syslog(SYSLOG_INFO, "sys: FAILED: %s - unable to change to Mail directory: %s", pw->pw_name, pw->pw_dir); #endif exit(111); } if (! pathexec_env("USER", pw->pw_name) || ! pathexec_env("HOME", pw->pw_dir) || ! pathexec_env("SHELL", pw->pw_shell)) { #if SYSLOG_LEVEL >= 3 syslog(SYSLOG_INFO, "sys: FAILED: %s - pathexec_env() failure(s)", pw->pw_name); #endif exit(111); } #if SYSLOG_LEVEL >= 3 syslog(SYSLOG_INFO, "sys: POP3 user %s : %s logged in from %s@%s [%s]", pw->pw_name, pw->pw_dir, remoteinfo, remotehost, remoteip); #endif pathexec(argv + 1); /* exit(111); */ return 0; }