diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-08-19 13:05:58 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2001-08-19 13:05:58 +0000 |
commit | a6a38350f779ddf3a6febf67dda7714fe368e492 (patch) | |
tree | b8ffbc248c20776618b1d6aa93ec16abb19e78d1 /usr.sbin/popa3d/pop_auth.c | |
parent | 580e400b41d341c2ad1bfe153d5ca6553351703a (diff) |
libexec is the wrong place for popa3d, since it can be started WITHOUT inetd
Diffstat (limited to 'usr.sbin/popa3d/pop_auth.c')
-rw-r--r-- | usr.sbin/popa3d/pop_auth.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/usr.sbin/popa3d/pop_auth.c b/usr.sbin/popa3d/pop_auth.c new file mode 100644 index 00000000000..65ea612d0bc --- /dev/null +++ b/usr.sbin/popa3d/pop_auth.c @@ -0,0 +1,89 @@ +/* $OpenBSD: pop_auth.c,v 1.1 2001/08/19 13:05:57 deraadt Exp $ */ + +/* + * AUTHORIZATION state handling. + */ + +#include <stdio.h> +#include <unistd.h> +#include <string.h> +#include <syslog.h> + +#include "misc.h" +#include "params.h" +#include "protocol.h" +#include "pop_auth.h" +#if POP_VIRTUAL +#include "virtual.h" +#endif + +static char *pop_user, *pop_pass; + +static int pop_auth_quit(char *params) +{ + if (params) return POP_ERROR; + return POP_LEAVE; +} + +static int pop_auth_user(char *params) +{ + char *user; + + user = pop_get_param(¶ms); + if (!user || pop_user || params) return POP_ERROR; + if (!(pop_user = strdup(user))) return POP_CRASH; + return POP_OK; +} + +static int pop_auth_pass(char *params) +{ + if (!params || !pop_user) return POP_ERROR; + if (!(pop_pass = strdup(params))) return POP_CRASH; + return POP_STATE; +} + +static struct pop_command pop_auth_commands[] = { + {"QUIT", pop_auth_quit}, + {"USER", pop_auth_user}, + {"PASS", pop_auth_pass}, + {NULL} +}; + +int do_pop_auth(int channel) +{ + pop_init(); + + if (pop_reply_ok()) return 1; + + pop_user = NULL; + if (pop_handle_state(pop_auth_commands) == POP_STATE) { + pop_clean(); + write_loop(channel, (char *)&pop_buffer, sizeof(pop_buffer)); + write_loop(channel, pop_user, strlen(pop_user) + 1); + write_loop(channel, pop_pass, strlen(pop_pass) + 1); + if (close(channel)) return 1; + } + + return 0; +} + +void log_pop_auth(int result, char *mailbox) +{ + if (result == AUTH_NONE) { + syslog(SYSLOG_PRIORITY, "Didn't attempt authentication"); + return; + } + +#if POP_VIRTUAL + if (virtual_domain) { + syslog(SYSLOG_PRIORITY, "Authentication %s for %s@%s", + result == AUTH_OK ? "passed" : "failed", + mailbox ? mailbox : "UNKNOWN", + virtual_domain); + return; + } +#endif + syslog(SYSLOG_PRIORITY, "Authentication %s for %s", + result == AUTH_OK ? "passed" : "failed", + mailbox ? mailbox : "UNKNOWN"); +} |