| version 1.1, 2003/01/07 21:59:41 |
version 1.2, 2003/01/12 14:30:39 |
|
|
| /* Alternative checkpassword for QPopup by Jedi/Sector One <j@4u.net> |
/* |
| |
* Alternative checkpassword for QPopup by Jedi/Sector One <j@4u.net> |
| * |
* |
| * Format of the configuration file is : |
* Format of the configuration file is : |
| * pop_login:crypted_password:real_login:path |
* pop_login:crypted_password:real_login:path |
|
|
| #include "../main.h" |
#include "../main.h" |
| |
|
| #ifndef CONFIG_FILE |
#ifndef CONFIG_FILE |
| # error Constant CONFIG_FILE not defined. Define in ../main.h. |
# error Constant CONFIG_FILE not defined. Define in ../main.h. |
| #endif |
#endif |
| |
|
| #include <stdlib.h> |
#include <stdlib.h> |
|
|
| #include <sys/types.h> |
#include <sys/types.h> |
| #include <pwd.h> |
#include <pwd.h> |
| #include <errno.h> |
#include <errno.h> |
| #include <syslog.h> |
|
| |
#ifndef SYSLOG_LEVEL |
| |
# error SYSLOG_LEVEL not defined |
| |
#else |
| |
# if SYSLOG_LEVEL >= 1 |
| |
# include <syslog.h> |
| |
# endif |
| |
#endif |
| |
|
| #ifndef LINE_MAX |
#ifndef LINE_MAX |
| # define LINE_MAX 2048 |
# define LINE_MAX 2048 |
| #endif |
#endif |
| |
|
| #ifndef LOGIN_MAX |
#ifndef LOGIN_MAX |
| # define LOGIN_MAX 16 |
# define LOGIN_MAX 16 |
| #endif |
#endif |
| |
|
| extern int errno; |
extern int errno; |
| Line 50 static char *str1e2(char *name, char *va |
|
| Line 58 static char *str1e2(char *name, char *va |
|
| char *nv; |
char *nv; |
| nv = malloc(strlen(name) + strlen(value) + 2); |
nv = malloc(strlen(name) + strlen(value) + 2); |
| if (!nv) { |
if (!nv) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]: exit 111 at point 1"); |
#if SYSLOG_LEVEL >= 1 |
| _exit(111); |
syslog(SYSLOG_ERROR, "user: exit 111 at point 1"); |
| |
#endif |
| |
exit(111); |
| } |
} |
| strcpy(nv,name); |
strcpy(nv,name); |
| strcat(nv,"="); |
strcat(nv,"="); |
| Line 76 static struct newpw { |
|
| Line 86 static struct newpw { |
|
| FILE *fp; |
FILE *fp; |
| |
|
| if ((fp = fopen(CONFIG_FILE, "rt")) == NULL) { |
if ((fp = fopen(CONFIG_FILE, "rt")) == NULL) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass[user]: exit 2 at point 2"); |
syslog(SYSLOG_ERROR, "user: exit 2 at point 2"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| |
|
| /* TODO: |
/* TODO: |
| Line 96 static struct newpw { |
|
| Line 107 static struct newpw { |
|
| *linepnt = 0; |
*linepnt = 0; |
| |
|
| if ((linepnt = strtok(line, ":")) == NULL) { |
if ((linepnt = strtok(line, ":")) == NULL) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass[user]: invalid line, aborting"); |
syslog(SYSLOG_ERROR, "user: invalid line, aborting"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| |
|
| if (strcmp(linepnt, newlogin) == 0) { |
if (strcmp(linepnt, newlogin) == 0) { |
| npw.pw_real = linepnt; |
npw.pw_real = linepnt; |
| if ((linepnt = strtok(NULL, ":")) == NULL) { |
if ((linepnt = strtok(NULL, ":")) == NULL) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass[user]: exit 2 at point 4"); |
syslog(SYSLOG_ERROR, "user: exit 2 at point 4"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| npw.pw_passwd = linepnt; |
npw.pw_passwd = linepnt; |
| if ((linepnt = strtok(NULL, ":")) == NULL) { |
if ((linepnt = strtok(NULL, ":")) == NULL) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass[user]: exit 2 at point 5"); |
syslog(SYSLOG_ERROR, "user: exit 2 at point 5"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| *(linepnt - 1) = 0; |
*(linepnt - 1) = 0; |
| tlogin = linepnt; |
tlogin = linepnt; |
| if ((linepnt = strtok(NULL, ":")) == NULL) { |
if ((linepnt = strtok(NULL, ":")) == NULL) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass[user]: exit 2 at point 6"); |
syslog(SYSLOG_ERROR, "user: exit 2 at point 6"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| npw.pw_dir = linepnt; |
npw.pw_dir = linepnt; |
| break; |
break; |
| Line 129 static struct newpw { |
|
| Line 144 static struct newpw { |
|
| fclose(fp); |
fclose(fp); |
| |
|
| if (tlogin == NULL) { |
if (tlogin == NULL) { |
| /* |
|
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]:" |
|
| " FAILED: %s - no such user from %s@%s [%s]", |
|
| newlogin, remoteinfo, remotehost, remoteip); |
|
| */ |
|
| return NULL; |
return NULL; |
| } |
} |
| |
|
| pw = getpwnam(tlogin); |
pw = getpwnam(tlogin); |
| if (!pw) { |
if (!pw) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]: exit 1 at point 8"); |
#if SYSLOG_LEVEL >= 1 |
| _exit(1); /* XXX: unfortunately getpwnam() hides temporary errors */ |
syslog(SYSLOG_ERROR, "user: exit 1 at point 8"); |
| |
#endif |
| |
exit(1); /* XXX: unfortunately getpwnam() hides temporary errors */ |
| } |
} |
| |
|
| npw.pw_name = tlogin; |
npw.pw_name = tlogin; |
| Line 166 int main_user(int argc, char **argv, cha |
|
| Line 178 int main_user(int argc, char **argv, cha |
|
| |
|
| pw = newgetpwnam(login); |
pw = newgetpwnam(login); |
| if (! pw) { |
if (! pw) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 3 |
| "atomicpop3pass[user]: FAILED: unknown username: %s", login); |
syslog(SYSLOG_INFO, "user: FAILED: unknown username: %s", login); |
| |
#endif |
| return -1; |
return -1; |
| } |
} |
| stored = pw->pw_passwd; |
stored = pw->pw_passwd; |
| Line 176 int main_user(int argc, char **argv, cha |
|
| Line 188 int main_user(int argc, char **argv, cha |
|
| encrypted = crypt(password, stored); |
encrypted = crypt(password, stored); |
| |
|
| if (!*stored || strcmp(encrypted,stored)) { |
if (!*stored || strcmp(encrypted,stored)) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]:" |
#if SYSLOG_LEVEL >= 3 |
| " FAILED: %s [%s] - password incorrect (%s) from %s@%s [%s]", |
syslog(SYSLOG_INFO, "user: FAILED: %s [%s]" |
| |
" - password incorrect (%s) from %s@%s [%s]", |
| login, pw->pw_real, password, remoteinfo, remotehost, remoteip); |
login, pw->pw_real, password, remoteinfo, remotehost, remoteip); |
| |
#endif |
| return -1; |
return -1; |
| } |
} |
| |
|
| Line 187 int main_user(int argc, char **argv, cha |
|
| Line 200 int main_user(int argc, char **argv, cha |
|
| nuke_dynamic_string(&password); |
nuke_dynamic_string(&password); |
| |
|
| if (!pw->pw_uid) { |
if (!pw->pw_uid) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]: exit 1 at point 15"); |
#if SYSLOG_LEVEL >= 1 |
| _exit(1); |
syslog(SYSLOG_ERROR, "user: exit 1 at point 15"); |
| |
#endif |
| |
exit(1); |
| } |
} |
| |
|
| /* pgregg - always use 888 |
/* pgregg - always use 888 |
| if (setgid(888) == -1) { */ |
if (setgid(888) == -1) { */ |
| if (setgid(pw->pw_gid) == -1) { |
if (setgid(pw->pw_gid) == -1) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]: exit 1 at point 16"); _exit(1); |
#if SYSLOG_LEVEL >= 1 |
| |
syslog(SYSLOG_ERROR, "user: exit 1 at point 16"); |
| |
#endif |
| |
exit(1); |
| } |
} |
| |
|
| if (setuid(pw->pw_uid) == -1) { |
if (setuid(pw->pw_uid) == -1) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass[user]: exit 1 at point 17"); |
syslog(SYSLOG_ERROR, "user: exit 1 at point 17"); |
| _exit(1); |
#endif |
| |
exit(1); |
| } |
} |
| |
|
| if (chdir(pw->pw_dir) == -1) { |
if (chdir(pw->pw_dir) == -1) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]:" |
#if SYSLOG_LEVEL >= 3 |
| " FAILED: %s - unable to change to Mail directory: %s", |
syslog(SYSLOG_INFO, "user: FAILED: %s" |
| |
" - unable to change to Mail directory: %s", |
| pw->pw_real, pw->pw_dir); |
pw->pw_real, pw->pw_dir); |
| _exit(111); |
#endif |
| |
exit(111); |
| } |
} |
| |
|
| if (getuid() < 500) { |
if (getuid() < 500) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]:" |
#if SYSLOG_LEVEL >= 3 |
| " DENIED: POP3 user's UID < 500"); |
syslog(SYSLOG_INFO, "user: DENIED: POP3 user's UID < 500"); |
| _exit(1); |
#endif |
| |
exit(1); |
| } |
} |
| |
|
| |
|
| Line 222 int main_user(int argc, char **argv, cha |
|
| Line 244 int main_user(int argc, char **argv, cha |
|
| ++numenv; |
++numenv; |
| newenv = (char **) malloc((numenv + 4) * sizeof(char *)); |
newenv = (char **) malloc((numenv + 4) * sizeof(char *)); |
| if (!newenv) { |
if (!newenv) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]:" |
#if SYSLOG_LEVEL >= 1 |
| " exit 111 at point 20 (%s)", argv[1]); |
syslog(SYSLOG_ERROR, "user: exit 111 at point 20 (%s)", argv[1]); |
| _exit(111); |
#endif |
| |
exit(111); |
| } |
} |
| |
|
| { |
{ |
| Line 240 int main_user(int argc, char **argv, cha |
|
| Line 263 int main_user(int argc, char **argv, cha |
|
| newenv[numenv] = 0; |
newenv[numenv] = 0; |
| environ = newenv; |
environ = newenv; |
| |
|
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass[user]:" |
#if SYSLOG_LEVEL >= 3 |
| |
syslog(SYSLOG_INFO, "user:" |
| " POP3 user %s : %s logged in from %s@%s [%s]", |
" POP3 user %s : %s logged in from %s@%s [%s]", |
| pw->pw_real, pw->pw_dir, remoteinfo, remotehost, remoteip); |
pw->pw_real, pw->pw_dir, remoteinfo, remotehost, remoteip); |
| |
#endif |
| |
|
| execvp(argv[1],argv + 1); |
execvp(argv[1],argv + 1); |
| _exit(111); |
exit(111); |
| |
|
| return 0; |
return 0; |
| } |
} |