| version 1.2, 2003/01/08 20:50:47 |
version 1.3, 2003/01/12 14:30:38 |
|
|
| * http://www.platon.sk/projects/libplaton/ |
* http://www.platon.sk/projects/libplaton/ |
| */ |
*/ |
| |
|
| /* |
/* $Platon: */ |
| * Written in 17/4/2002. |
|
| * |
|
| * version 0.1 - 05:15 - sys login worked, user login not |
|
| * version 0.2 - 16:00 - sys login and user login not worked |
|
| * version 0.3 - 19:30 - sys login and user login worked |
|
| * version 0.3.1 - 19:43 - specials login and password strings protections |
|
| */ |
|
| |
|
| #include <stdio.h> |
#include <stdio.h> |
| #include <string.h> |
#include <string.h> |
| #include <stdlib.h> |
#include <stdlib.h> |
| #include <unistd.h> |
#include <unistd.h> |
| #include <syslog.h> |
|
| #include <errno.h> |
#include <errno.h> |
| |
|
| #include "main.h" |
#include "main.h" |
| #include "sys/main.h" |
#include "sys/main.h" |
| #include "user/main.h" |
#include "user/main.h" |
| |
|
| char *login = NULL; |
#ifndef SYSLOG_LEVEL |
| |
# error SYSLOG_LEVEL not defined |
| |
#else |
| |
# if SYSLOG_LEVEL >= 1 |
| |
# include <syslog.h> |
| |
# endif |
| |
#endif |
| |
|
| |
char *login = NULL; |
| char *password = NULL; |
char *password = NULL; |
| |
|
| char remotehost[BUFLEN] = "\0"; |
char remotehost[BUFLEN] = "\0"; |
| char remoteip[BUFLEN] = "\0"; |
char remoteip[BUFLEN] = "\0"; |
| char remoteinfo[BUFLEN] = "unknown\0"; |
char remoteinfo[BUFLEN] = "unknown\0"; |
| |
|
| |
int main(int argc, char **argv, char *envp[]) /* {{{ */ |
| /* Function int main(int argc, char **argv) {{{ */ |
|
| int main(int argc, char **argv, char *envp[]) |
|
| { |
{ |
| int r; |
int r; |
| int i; |
int i; |
| Line 53 int main(int argc, char **argv, char *en |
|
| Line 51 int main(int argc, char **argv, char *en |
|
| char **me; |
char **me; |
| |
|
| if (! argv[1]) |
if (! argv[1]) |
| _exit(2); |
exit(2); |
| |
|
| #if DEBUG |
#if SYSLOG_LEVEL >= 1 |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass: debug: started"); |
/* Opening log */ |
| |
openlog(PROGRAM_NAME, LOG_PID, SYSLOG_FACILITY); |
| |
#endif |
| |
|
| |
if (atexit(atexit_function0) == -1) { |
| |
#if SYSLOG_LEVEL >= 1 |
| |
syslog(SYSLOG_ERROR, "cannot register atexit() function"); |
| |
exit(2); |
| |
#endif |
| |
} |
| |
|
| |
#if SYSLOG_LEVEL >= 9 |
| |
syslog(SYSLOG_DEBUG, "debug: started"); |
| #endif |
#endif |
| |
|
| for (me = envp; *me; me++) { |
for (me = envp; *me; me++) { |
| Line 79 int main(int argc, char **argv, char *en |
|
| Line 89 int main(int argc, char **argv, char *en |
|
| } |
} |
| } |
} |
| |
|
| #if DEBUG |
#if SYSLOG_LEVEL >= 9 |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass: debug:" |
syslog(SYSLOG_DEBUG, "debug: POP3 connect from %s@%s [%s]", |
| " POP3 connect from %s@%s [%s]", |
|
| remoteinfo, remotehost, remoteip); |
remoteinfo, remotehost, remoteip); |
| #endif |
#endif |
| |
|
| if (argc < 2) { |
if (argc < 2) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass: exit 2 at point 9 (bad argc)"); |
syslog(SYSLOG_ERROR, "exit 2 at point 9 (bad argc)"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| |
|
| uplen = 0; |
uplen = 0; |
| Line 97 int main(int argc, char **argv, char *en |
|
| Line 107 int main(int argc, char **argv, char *en |
|
| r = read(3, up + uplen,sizeof(up) - uplen); |
r = read(3, up + uplen,sizeof(up) - uplen); |
| } while ((r == -1) && (errno == EINTR)); |
} while ((r == -1) && (errno == EINTR)); |
| if (r == -1) |
if (r == -1) |
| _exit(111); |
exit(111); |
| if (r == 0) |
if (r == 0) |
| break; |
break; |
| uplen += r; |
uplen += r; |
| if (uplen >= sizeof(up)) |
if (uplen >= sizeof(up)) |
| _exit(1); |
exit(1); |
| } |
} |
| |
|
| close(3); |
close(3); |
| Line 111 int main(int argc, char **argv, char *en |
|
| Line 121 int main(int argc, char **argv, char *en |
|
| login = up + i; |
login = up + i; |
| while (up[i++]) |
while (up[i++]) |
| if (i == uplen) { |
if (i == uplen) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass: exit 2 at point 10"); |
syslog(SYSLOG_ERROR, "exit 2 at point 10"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| |
|
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass:" |
#if SYSLOG_LEVEL >= 5 |
| " POP3 user %s connected from %s@%s [%s]", |
syslog(SYSLOG_INFO, "POP3 user %s connected from %s@%s [%s]", |
| login, remoteinfo, remotehost, remoteip); |
login, remoteinfo, remotehost, remoteip); |
| |
#endif |
| |
|
| password = up + i; |
password = up + i; |
| if (i == uplen) { |
if (i == uplen) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass: exit 2 at point 11"); |
#if SYSLOG_LEVEL >= 1 |
| _exit(2); |
syslog(SYSLOG_ERROR, "exit 2 at point 11"); |
| |
#endif |
| |
exit(2); |
| } |
} |
| while (up[i++]) |
while (up[i++]) |
| if (i == uplen) { |
if (i == uplen) { |
| syslog(LOG_AUTH | LOG_WARNING, |
#if SYSLOG_LEVEL >= 1 |
| "atomicpop3pass: exit 2 at point 12"); |
syslog(SYSLOG_ERROR, "exit 2 at point 12"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| |
|
| if (! login || ! password) { |
if (! login || ! password) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass:" |
#if SYSLOG_LEVEL >= 1 |
| " sorry, NULL login or password, cannot proceed"); |
syslog(SYSLOG_ERROR, "sorry, NULL login or password, cannot proceed"); |
| _exit(2); |
#endif |
| |
exit(2); |
| } |
} |
| else { |
else { |
| #if DEBUG |
#if SYSLOG_LEVEL >= 9 |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass:" |
syslog(SYSLOG_DEBUG, "debug: login = %s, pass = %s", login, password); |
| " debug: login = %s, pass = %s", |
|
| login, password); |
|
| #endif |
#endif |
| } |
} |
| |
|
| login = strdup(login); |
login = strdup(login); |
| password = strdup(password); |
password = strdup(password); |
| |
|
| /* Clear input username/passwd stack. */ |
/* Clear input username/passwd stack. */ |
| Line 156 int main(int argc, char **argv, char *en |
|
| Line 170 int main(int argc, char **argv, char *en |
|
| /* System login failed. |
/* System login failed. |
| We are going to try user defined login. */ |
We are going to try user defined login. */ |
| |
|
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass:" |
#if SYSLOG_LEVEL >= 5 |
| " system login failed, trying user login"); |
syslog(SYSLOG_INFO, "system login failed, trying user login"); |
| |
#endif |
| |
|
| if (main_user(argc, argv, envp) < 0) { |
if (main_user(argc, argv, envp) < 0) { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass:" |
#if SYSLOG_LEVEL >= 5 |
| " user login failed, aborting"); |
syslog(SYSLOG_INFO, "user login failed, aborting"); |
| |
#endif |
| |
|
| /* sleep() to |
/* sleep() to |
| 1. allow syslog to work and |
1. allow syslog to work and |
| Line 170 int main(int argc, char **argv, char *en |
|
| Line 186 int main(int argc, char **argv, char *en |
|
| sleep(SLEEP); |
sleep(SLEEP); |
| } |
} |
| else { |
else { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass:" |
#if SYSLOG_LEVEL >= 1 |
| " execvp() failure in user login"); |
syslog(SYSLOG_ERROR, "execvp() failure in user login"); |
| |
#endif |
| } |
} |
| } |
} |
| else { |
else { |
| syslog(LOG_AUTH | LOG_WARNING, "atomicpop3pass:" |
#if SYSLOG_LEVEL >= 1 |
| " pathexec()/execve() failure in system login"); |
syslog(SYSLOG_ERROR, "pathexec()/execve() failure in system login"); |
| |
#endif |
| } |
} |
| |
|
| nuke_dynamic_string(&login); |
nuke_dynamic_string(&login); |
| nuke_dynamic_string(&password); |
nuke_dynamic_string(&password); |
| |
|
| _exit(111); |
exit(111); |
| |
|
| /* We should never get here. */ |
/* We should never reach this. */ |
| return 0; |
return 0; |
| } /* }}} */ |
} /* }}} */ |
| |
|
| /* Function void nuke_dynamic_string(char **str) {{{ */ |
void atexit_function0(void) /* {{{ */ |
| void nuke_dynamic_string(char **str) |
{ |
| |
#if SYSLOG_LEVEL >= 1 |
| |
closelog(); |
| |
#endif |
| |
} /* }}} */ |
| |
|
| |
void nuke_dynamic_string(char **str) /* {{{ */ |
| { |
{ |
| if (str != NULL || *str != NULL) { |
if (str != NULL || *str != NULL) { |
| register char *s; |
register char *s; |
| Line 202 void nuke_dynamic_string(char **str) |
|
| Line 226 void nuke_dynamic_string(char **str) |
|
| } |
} |
| } /* }}} */ |
} /* }}} */ |
| |
|
| |
|
| /* Modeline for ViM {{{ |
/* Modeline for ViM {{{ |
| * vim:set ts=4: |
* vim:set ts=4: |
| * vim600:fdm=marker fdl=0 fdc=3: |
* vim600:fdm=marker fdl=0 fdc=0: |
| * }}} */ |
* }}} */ |
| |
|
| |
|