summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlain Magloire <alainm@gnu.org>2001-05-20 02:37:38 +0000
committerAlain Magloire <alainm@gnu.org>2001-05-20 02:37:38 +0000
commit83ea18f24c9dbf255e02a4d3a6632467432be4a8 (patch)
tree4689fdc9ea636e5e101a386a13f081bb91fabbc8
parenta9a11cf95bbfad541ae242cffecb963065621fa1 (diff)
downloadmailutils-83ea18f24c9dbf255e02a4d3a6632467432be4a8.tar.gz
mailutils-83ea18f24c9dbf255e02a4d3a6632467432be4a8.tar.bz2
Not to use mailbox_create_defaut.
-rw-r--r--pop3d/apop.c51
-rw-r--r--pop3d/pop3d.h6
-rw-r--r--pop3d/user.c12
3 files changed, 37 insertions, 32 deletions
diff --git a/pop3d/apop.c b/pop3d/apop.c
index 6d73f1395..3935b3fcc 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -148,13 +148,14 @@ pop3d_apopuser (const char *user)
int
pop3d_apop (const char *arg)
{
- char *tmp, *user_digest, *password;
+ char *tmp, *user_digest, *user, *password;
struct passwd *pw;
char buf[POP_MAXCMDLEN];
struct md5_ctx md5context;
unsigned char md5digest[16];
int status;
int lockit = 1;
+ char *mailbox_name = NULL;
if (state != AUTHORIZATION)
return ERR_WRONG_STATE;
@@ -162,20 +163,18 @@ pop3d_apop (const char *arg)
if (strlen (arg) == 0)
return ERR_BAD_ARGS;
- username = pop3d_cmd (arg);
- if (strlen (username) > (POP_MAXCMDLEN - APOP_DIGEST))
+ user = pop3d_cmd (arg);
+ if (strlen (user) > (POP_MAXCMDLEN - APOP_DIGEST))
{
- free (username);
- username = NULL;
+ free (user);
return ERR_BAD_ARGS;
}
user_digest = pop3d_args (arg);
- password = pop3d_apopuser (username);
+ password = pop3d_apopuser (user);
if (password == NULL)
{
- free (username);
- username = NULL;
+ free (user);
free (user_digest);
return ERR_BAD_LOGIN;
}
@@ -197,30 +196,26 @@ pop3d_apop (const char *arg)
if (strcmp (user_digest, buf))
{
- free (username);
- username = NULL;
+ free (user);
free (user_digest);
return ERR_BAD_LOGIN;
}
free (user_digest);
- pw = getpwnam (username);
+ pw = getpwnam (user);
+ free (user);
if (pw == NULL)
- {
- free (username);
- username = NULL;
- return ERR_BAD_LOGIN;
- }
+ return ERR_BAD_LOGIN;
/* Reset the uid. */
if (setuid (pw->pw_uid) == -1)
- {
- free (username);
- username = NULL;
- return ERR_BAD_LOGIN;
- }
+ return ERR_BAD_LOGIN;
+
+ mailbox_name = calloc (strlen (_PATH_MAILDIR) + 1
+ + strlen (pw->pw_name) + 1, 1);
+ sprintf (mailbox_name, "%s/%s", _PATH_MAILDIR, pw->pw_name);
- if ((status = mailbox_create_default (&mbox, username)) != 0
+ if ((status = mailbox_create (&mbox, mailbox_name)) != 0
|| (status = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
{
mailbox_destroy (&mbox);
@@ -230,33 +225,33 @@ pop3d_apop (const char *arg)
if (mailbox_create (&mbox, "/dev/null") != 0
|| mailbox_open (mbox, MU_STREAM_READ) != 0)
{
- free (username);
- username = NULL;
+ free (mailbox_name);
state = AUTHORIZATION;
return ERR_UNKNOWN;
}
}
else
{
- free (username);
- username = NULL;
+ free (mailbox_name);
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
lockit = 0; /* Do not attempt to lock /dev/null ! */
}
+ free (mailbox_name);
if (lockit && pop3d_lock())
{
mailbox_close(mbox);
mailbox_destroy(&mbox);
state = AUTHORIZATION;
- free (username);
- username = NULL;
return ERR_MBOX_LOCK;
}
state = TRANSACTION;
+ username = strdup (pw->pw_name);
+ if (username == NULL)
+ pop3d_abquit (ERR_NO_MEM);
fprintf (ofile, "+OK opened mailbox for %s\r\n", username);
/* mailbox name */
{
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index a8ff68be6..0cdcea7b8 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -114,8 +114,10 @@
/* The path to the mail spool files */
#ifdef HAVE_PATHS_H
#include <paths.h>
-#else
-#define _PATH_MAILDIR "/usr/spool/mail"
+#endif
+
+#ifndef _PATH_MAILDIR
+# define _PATH_MAILDIR "/usr/spool/mail"
#endif
#ifdef HAVE_SECURITY_PAM_APPL_H
diff --git a/pop3d/user.c b/pop3d/user.c
index a40ccc7af..092027e31 100644
--- a/pop3d/user.c
+++ b/pop3d/user.c
@@ -83,6 +83,7 @@ pop3d_user (const char *arg)
struct passwd *pw;
int status;
int lockit = 1;
+ char *mailbox_name;
if (state != AUTHORIZATION)
return ERR_WRONG_STATE;
@@ -179,7 +180,11 @@ pop3d_user (const char *arg)
if (pw != NULL && pw->pw_uid > 1)
setuid (pw->pw_uid);
- if ((status = mailbox_create_default (&mbox, arg)) != 0
+ mailbox_name = calloc (strlen (_PATH_MAILDIR) + 1
+ + strlen (pw->pw_name) + 1, 1);
+ sprintf (mailbox_name, "%s/%s", _PATH_MAILDIR, pw->pw_name);
+
+ if ((status = mailbox_create (&mbox, mailbox_name)) != 0
|| (status = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
{
mailbox_destroy (&mbox);
@@ -190,16 +195,19 @@ pop3d_user (const char *arg)
|| mailbox_open (mbox, MU_STREAM_READ) != 0)
{
state = AUTHORIZATION;
+ free (mailbox_name);
return ERR_UNKNOWN;
}
}
else
{
state = AUTHORIZATION;
+ free (mailbox_name);
return ERR_MBOX_LOCK;
}
lockit = 0; /* Do not attempt to lock /dev/null ! */
}
+ free (mailbox_name);
if (lockit && pop3d_lock())
{
@@ -209,7 +217,7 @@ pop3d_user (const char *arg)
return ERR_MBOX_LOCK;
}
- username = strdup (arg);
+ username = strdup (pw->pw_name);
if (username == NULL)
pop3d_abquit (ERR_NO_MEM);
state = TRANSACTION;

Return to:

Send suggestions and report system problems to the System administrator.