Commit 35a57822 35a57822acbf8632729b269844bdcd414a076d6b by Jakob Kaivo

Variuos code cleanups

fixed a couple of functions to use libmailbox
fixed copyright notices
1 parent 31fcf857
......@@ -6,4 +6,10 @@ pop3d_DEPENDENDENCIES = ../libmailbox/libmailbox.la ../libsrc/libgetopt.la\
../libsrc/libmd5.la
pop3d_SOURCES = apop.c auth.c capa.c dele.c extra.c pop3d.c pop3d.h\
list.c noop.c quit.c retr.c rset.c stat.c top.c uidl.c user.c
pop3d_LDADD = ../libmailbox/libmailbox.la
\ No newline at end of file
#if USE_LIBPAM
#pop3d_LDADD = ../libmailbox/libmailbox.la -lpam -ldl
#else
#pop3d_LDADD = ../libmailbox/libmailbox.la
#endif
pop3d_LADADD = ../libmailbox/libmailbox.la $(AUTHLIBS)
\ No newline at end of file
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -17,8 +17,6 @@
#include "pop3d.h"
#ifdef _USE_APOP
/* Check if a username exists in APOP password file
returns pinter to password if found, otherwise NULL */
char *
......@@ -127,30 +125,26 @@ pop3_apop (const char *arg)
if (state != AUTHORIZATION)
return ERR_WRONG_STATE;
if (strlen (arg) == 0)
return ERR_BAD_ARGS;
tmp = pop3_cmd (arg);
if (strlen (tmp) > (POP_MAXCMDLEN - APOP_DIGEST))
if (strlen (arg) == 0)
return ERR_BAD_ARGS;
if ((username = strdup (tmp)) == NULL)
pop3_abquit (ERR_NO_MEM);
free (tmp);
tmp = pop3_args (arg);
if (strlen (tmp) > APOP_DIGEST)
username = pop3_cmd (arg);
user_digest = pop3_args (arg);
if (strlen (username) > (POP_MAXCMDLEN - APOP_DIGEST))
return ERR_BAD_ARGS;
if ((user_digest = strdup (tmp)) == NULL)
pop3_abquit (ERR_NO_MEM);
free (tmp);
if ((password = pop3_apopuser (username)) == NULL)
return ERR_BAD_LOGIN;
password = pop3_apopuser (username);
if (password == NULL)
{
free (username);
free (user_digest);
return ERR_BAD_LOGIN;
}
md5_init_ctx (&md5context);
md5_process_bytes (md5shared, strlen (md5shared), &md5context);
md5_process_bytes (password, strlen (password), &md5context);
/* pop3_wipestr (password); */
free (password);
md5_finish_ctx (&md5context, md5digest);
......@@ -161,49 +155,44 @@ pop3_apop (const char *arg)
*tmp++ = '\0';
if (strcmp (user_digest, buf))
return ERR_BAD_LOGIN;
{
free (username);
free (user_digest);
return ERR_BAD_LOGIN;
}
if ((pw = getpwnam (username)) == NULL)
return ERR_BAD_LOGIN;
free (user_digest);
pw = getpwnam (username);
if (pw == NULL)
{
free (username);
return ERR_BAD_LOGIN;
}
#ifdef MAILSPOOLHOME
mailbox = malloc ((strlen (pw->pw_dir) + strlen (MAILSPOOLHOME) + 1) * sizeof (char));
if (mailbox == NULL)
pop3_abquit (ERR_NO_MEM);
strcpy (mailbox, pw->pw_dir);
strcat (mailbox, MAILSPOOLHOME);
mbox = fopen (mailbox, "r");
if (pw != NULL)
{
chdir (pw->pw_dir);
mbox = mbox_open (MAILSPOOLHOME);
}
else
mbox = NULL;
if (mbox == NULL)
{
free (mailbox);
chdir (_PATH_MAILDIR);
#endif
mailbox = malloc (sizeof (char) * (strlen (_PATH_MAILDIR) + strlen (username) + 2));
strcpy (mailbox, _PATH_MAILDIR "/");
strcat (mailbox, username);
if (mailbox == NULL)
pop3_abquit (ERR_NO_MEM);
mbox = fopen (mailbox, "r");
#endif /* MAILSPOOLHOME */
mbox = mbox_open (username);
if (mbox == NULL)
{
mailbox = strdup ("/dev/null");
if (mailbox == NULL)
pop3_abquit (ERR_NO_MEM);
mbox = fopen (mailbox, "r");
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
#ifdef MAILSPOOLHOME
}
else
#endif
if (pop3_lock () != OK)
{
pop3_unlock ();
free (mailbox);
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
#if 0
if ((pw->pw_uid < 1)
#ifdef MAILSPOOLHOME
/* Drop mail group for home dirs */
......@@ -215,22 +204,11 @@ pop3_apop (const char *arg)
free (mailbox);
return ERR_BAD_LOGIN;
}
#endif /* 0 */
state = TRANSACTION;
messages = NULL;
pop3_getsizes ();
fprintf (ofile, "+OK opened mailbox for %s\r\n", username);
syslog (LOG_INFO, "User %s logged in with mailbox %s", username, mailbox);
cursor = 0;
syslog (LOG_INFO, "User %s logged in with mailbox %s", username, mbox->name);
return OK;
}
#else
int
pop3_apop (const char *foo)
{
return ERR_NOT_IMPL;
}
#endif
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
* Code for capa support by Sean 'Shaleh' Perry <shaleh@debian.org>
* added 4/2/1999
*
*/
#include "pop3d.h"
int
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -33,16 +33,15 @@ pop3_retr (const char *arg)
mesg = atoi (arg) - 1;
if (mesg > mbox->messages || mbox_is_deleted(mbox, mesg))
if (mesg >= mbox->messages || mbox_is_deleted(mbox, mesg))
return ERR_NO_MESG;
fprintf (ofile, "+OK\r\n");
buf = mbox_get_header (mbox, mesg);
fprintf (ofile, "%s", buf);
fprintf (ofile, "+OK\r\n%s\r\n", buf);
free (buf);
buf = mbox_get_body (mbox, mesg);
fprintf (ofile, "%s", buf);
fprintf (ofile, "%s.\r\n", buf);
free (buf);
fprintf (ofile, ".\r\n");
return OK;
}
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -22,11 +22,9 @@
int
pop3_top (const char *arg)
{
#ifdef _HAVE_BLACK_MAGIC
int i = 0, header = 1, done = 0;
int mesg, lines;
char *mesgc, *linesc;
char *buf, buf2[80];
char *buf;
if (strlen (arg) == 0)
return ERR_BAD_ARGS;
......@@ -44,66 +42,15 @@ pop3_top (const char *arg)
if (lines < 0)
return ERR_BAD_ARGS;
if (pop3_mesg_exist (mesg) != OK)
if (mesg > mbox->messages || mbox_is_deleted(mbox, mesg))
return ERR_NO_MESG;
mbox = freopen (mailbox, "r", mbox);
if (mbox == NULL)
return ERR_FILE;
fsetpos (mbox, &(messages[mesg].header));
fprintf (ofile, "+OK\r\n");
buf = malloc (sizeof (char) * 80);
if (buf == NULL)
pop3_abquit (ERR_NO_MEM);
while (fgets (buf, 80, mbox) && !done)
{
while (strchr (buf, '\n') == NULL)
{
buf = realloc (buf, sizeof (char) * (strlen (buf) + 81));
if (buf == NULL)
pop3_abquit (ERR_NO_MEM);
fgets (buf2, 80, mbox);
strncat (buf, buf2, 80);
}
if (!strncmp (buf, "From ", 5))
done = 1;
else
{
buf[strlen (buf) - 1] = '\0';
if (header == 1)
{
if (buf[0] == '.')
fprintf (ofile, ".%s\r\n", buf);
else
fprintf (ofile, "%s\r\n", buf);
if ((buf[0] == '\r') || (buf[0] == '\n') || (buf[0]) == '\0')
header = 0;
}
else
{
if (++i <= lines)
{
if (buf[0] == '.')
fprintf (ofile, ".%s\r\n", buf);
else
fprintf (ofile, "%s\r\n", buf);
}
else
done = 1;
}
}
buf = realloc (buf, sizeof (char) * 80);
if (buf == NULL)
pop3_abquit (ERR_NO_MEM);
}
buf = mbox_get_header (mbox, mesg);
fprintf (ofile, "+OK\r\n%s\r\n", buf);
free (buf);
buf = mbox_body_lines (mbox, mesg, lines);
fprintf (ofile, "%s.\r\n", buf);
free (buf);
fprintf (ofile, ".\r\n");
return OK;
#else
return ERR_NOT_IMPL;
#endif
}
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/* GNU POP3 - a small, fast, and efficient POP3 daemon
Copyright (C) 1999 Jakob 'sparky' Kaivo <jkaivo@nodomainname.net>
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -79,11 +79,11 @@ int
pop3_user (const char *arg)
{
char *buf, pass[POP_MAXCMDLEN], *tmp, *cmd;
struct passwd *pw;
#ifdef USE_LIBPAM
pam_handle_t *pamh;
int pamerror;
#endif /* !USE_LIBPAM */
struct passwd *pw;
if (state != AUTHORIZATION)
return ERR_WRONG_STATE;
......@@ -101,6 +101,7 @@ pop3_user (const char *arg)
if (strlen (tmp) > POP_MAXCMDLEN)
{
free (cmd);
free (tmp);
return ERR_TOO_LONG;
}
......@@ -148,7 +149,7 @@ pop3_user (const char *arg)
#endif /* HAVE_SHADOW_H */
return ERR_BAD_LOGIN;
}
#else /* USE_LIBPAM */
#else /* !USE_LIBPAM */
_user = (char *) arg;
_pwd = pass;
/* libpam doesn't log to LOG_MAIL */
......@@ -166,18 +167,21 @@ pop3_user (const char *arg)
#endif /* USE_LIBPAM */
#ifdef MAILSPOOLHOME
chdir (pw->pw_dir);
mbox = mbox_open (MAILSPOOLHOME);
if (mbox == NULL)
if (pw != NULL)
{
chdir (pw->pw_dir);
mbox = mbox_open (MAILSPOOLHOME);
}
else
mbox = NULL;
if (mbox == NULL) /* We should check errno here... */
{
/* See comments below... */
chdir (_PATH_MAILDIR);
#endif /* MAILSPOOLHOME */
mbox = mbox_open (arg);
if (mbox == NULL)
if (mbox == NULL) /* And here */
{
/* Check the error type... */
/* Until then, though */
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
......@@ -192,6 +196,8 @@ pop3_user (const char *arg)
if (pw != NULL && pw->pw_uid > 1)
setuid (pw->pw_uid);
mbox_lock (mbox, MO_RLOCK | MO_WLOCK);
fprintf (ofile, "+OK opened mailbox for %s\r\n", username);
syslog (LOG_INFO, "User '%s' logged in with mailbox '%s'", username,
mbox->name);
......