Commit e94e8805 e94e8805cc5b73ef8710f58892fbce83d074b084 by Alain Magloire

Patches from Sergey, se Changelog for details:

2001-04-23 Sergey Poznyakoff
1 parent e73d4524
2001-05-03 Alain Magloire
* argp/argp-help.c (hol_entry_help): Some compiler like Watcomm
can not initialize a local structure struct .. = { .. }. Do it
explicitely field by field.
* argp/arpg-parse.c: Watcomm choke on N_() macro.
(parser_init): Watcomm does not like operation on a void * pointer.
* imap4d/login.c: Cast the return of crypt(), since some platforms
do not provide a prototype in <unistd.h>
* pop3d/user.c: Cast the return of crypt(), since in may not be
declare in <unistd.h>.
* lib/snprintf.c: Use only __STDC__ to detect <stdar.h>
* lib/snprintf.h: Use only __STDC__.
* mail/mail.h: The global variable should be declare extern.
* mail/pipe.c: Use 512 buffer instead of BUFSIZ, go easy on the stack.
* mail/print.c: Use 512 buffer instead of BUFSIZ, go easy on the stack.
* mail/write.c: Use 512 buffer instead of BUFSIZ, go easy on the stack.
* mailbox/folder_imap.c: Declare strtock_r ().
2001-05-03 Sergey Poznyakoff
* pop3d/user.c: Misplace parentheses around the mailbox_xx() calls.
Do not free (buf) since it is now static storage. Unfortunately most
of the pam modules do openlog() on their own, thus after
authentication all logging output flows to where the last pam module
has directed it, which is usually `auth' facility.
Put back closelog()/openlog().
* pop3d/pop3d.h: ifile is now FILE *.
pop3d_realine () take FILE * as a prototype.
* pop3d/pop3d.c (pop3d_mainloop): Refresh lock, pop3d_touchlock().
Register SIGALRM in the child.
Do not free (buf) since it is now static storage.
* pop3d/extra.c (pop3d_readline): Change to use
fgets () and alarm ().
With small modification from Alain.
(pop3d_signal): ofile will be NULL in the *child* process:
whereas in the parent one, ofile will always be NULL, since it lives
in the BSS (FILE *ofile;) and gets initialized only in the child
process. Thus, when the parent receives any signal, SIGTERM for
example, it does pop3d_abquit(ERR_SIGNAL) and dies doing
fprintf(ofile, ...)
2001-05-02 Alain Magloire
Some of the Makefile.am contain gcc specific options
......
......@@ -1054,7 +1054,14 @@ hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
int old_wm = __argp_fmtstream_wmargin (stream);
/* PEST is a state block holding some of our variables that we'd like to
share with helper functions. */
struct pentry_state pest = { entry, stream, hhstate, 1, state };
/* Some loosing compiler can not handle this ... lets play nice. */
/* struct pentry_state pest = { entry, stream, hhstate, 1, state }; */
struct pentry_state pest;
pest.entry = entry;
pest.stream = stream;
pest.hhstate = hhstate;
pest.first = 1;
pest.state = state;
if (! odoc (real))
for (opt = real, num = entry->num; num > 0; opt++, num--)
......
......@@ -43,7 +43,7 @@
# endif
#endif
#ifndef N_
# define N_(msgid) (msgid)
# define N_(msgid) msgid
#endif
#if _LIBC - 0
......@@ -525,9 +525,14 @@ parser_init (struct parser *parser, const struct argp *argp,
return ENOMEM;
parser->groups = parser->storage;
/* To please Watcom CC
parser->child_inputs = parser->storage + GLEN;
parser->long_opts = parser->storage + GLEN + CLEN;
parser->short_opts = parser->storage + GLEN + CLEN + LLEN;
*/
parser->child_inputs = (char *)(parser->storage) + GLEN;
parser->long_opts = (char *)(parser->storage) + GLEN + CLEN;
parser->short_opts = (char *)(parser->storage) + GLEN + CLEN + LLEN;
memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *));
parser_convert (parser, argp, flags);
......
......@@ -100,7 +100,7 @@ imap4d_login (struct imap4d_command *command, char *arg)
#ifndef USE_LIBPAM
if (pw == NULL || pw->pw_uid < 1)
return util_finish (command, RESP_NO, "User name or passwd rejected");
if (strcmp (pw->pw_passwd, crypt (pass, pw->pw_passwd)))
if (strcmp (pw->pw_passwd, (char *)crypt (pass, pw->pw_passwd)))
{
#ifdef HAVE_SHADOW_H
struct spwd *spw;
......
......@@ -18,8 +18,8 @@
#include "imap4d.h"
/*
*
*/
FIXME: Renaming a mailbox we must change the UIDVALIDITY
of the mailbox. */
int
imap4d_rename (struct imap4d_command *command, char *arg)
......
......@@ -340,6 +340,51 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...)
return status;
}
#if 0
/* Need a replacement for readline that can support literals. */
char *
imap4d_readline (FILE *fp)
{
char buffer[512];
char *line;
size_t len;
alarm (timeout);
line = fgets (buffer, sizeof (buffer), fp);
alarm (0);
if (!line)
util_quit (1);
line = strdup (buffer);
len = strlen (buffer);
if (len > 2)
{
len--; /* C arrays are 0-based. */
if (line[len] == '\n' && line[len - 1] == '}')
{
while (len && line[len] != '{') len--;
if (line [len] == '{')
{
char *sp = NULL;
long number = strtoul (line + len + 1, &sp, 10);
if (*sp != '+')
util_send ("+ GO AHEAD\r\n");
line[len] = '\0';
while (number > 0)
{
char *literal = imap4d_readline (fd);
size_t n = strlen (literal);
line = realloc (line, strlen (line) + n + 1);
strcat (line, literal);
number -= n;
free (literal);
}
}
}
}
return line;
}
#endif
char *
imap4d_readline (int fd)
{
......
......@@ -642,7 +642,7 @@ va_list args;
#ifndef HAVE_SNPRINTF
PUBLIC int
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
#if __STDC__
snprintf(char *string, size_t length, const char * format, ...)
#else
snprintf(string, length, format, va_alist)
......@@ -655,7 +655,7 @@ va_dcl
int rval;
va_list args;
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
#if __STDC__
va_start(args, format);
#else
va_start(args);
......
......@@ -39,7 +39,7 @@ Alain Magloire: alainm@rcsm.ee.mcgill.ca
#include <config.h>
#endif
#if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
......
......@@ -17,6 +17,13 @@
#include "mail.h"
/* Global variables and constants*/
mailbox_t mbox;
unsigned int cursor;
unsigned int realcursor;
unsigned int total;
FILE *ofile;
const char *argp_program_version = "mail (" PACKAGE ") " VERSION;
const char *argp_program_bug_address = "<bug-mailutils@gnu.org>";
static char doc[] = "GNU mail -- the standard /bin/mail interface";
......
......@@ -83,11 +83,11 @@ struct mail_env_entry {
};
/* Global variables and constants*/
mailbox_t mbox;
unsigned int cursor;
unsigned int realcursor;
unsigned int total;
FILE *ofile;
extern mailbox_t mbox;
extern unsigned int cursor;
extern unsigned int realcursor;
extern unsigned int total;
extern FILE *ofile;
extern const struct mail_command_entry mail_command_table[];
/* Functions */
......
......@@ -30,7 +30,7 @@ mail_pipe (int argc, char **argv)
char *cmd;
FILE *pipe;
int *list, num = 0;
char buffer[BUFSIZ];
char buffer[512];
off_t off = 0;
size_t n = 0;
......
......@@ -36,7 +36,7 @@ mail_print (int argc, char **argv)
header_t hdr;
body_t body;
stream_t stream;
char buffer[BUFSIZ];
char buffer[512];
off_t off = 0;
size_t n = 0, lines = 0;
FILE *out = ofile;
......
......@@ -30,7 +30,7 @@ mail_top (int argc, char **argv)
{
message_t msg;
stream_t stream;
char buf[BUFSIZ];
char buf[512];
size_t n;
off_t off;
int lines = strtol ((util_find_env("toplines"))->value, NULL, 10);
......
......@@ -35,7 +35,7 @@ mail_write (int argc, char **argv)
stream_t stream;
FILE *output;
char *filename = NULL;
char buffer[BUFSIZ];
char buffer[512];
off_t off = 0;
size_t n = 0;
int *msglist = NULL;
......
......@@ -58,6 +58,9 @@ static struct _record _imap_record =
via the register entry/record. */
record_t imap_record = &_imap_record;
#ifndef HAVE_STRTOK_R
char *strtok_r __P ((char *, const char *, char **));
#endif
/* Concrete IMAP implementation. */
static int folder_imap_open __P ((folder_t, int));
static int folder_imap_create __P ((folder_t));
......
......@@ -69,8 +69,8 @@ pop3d_apopuser (const char *user)
return NULL;
}
memset (&key, 0, sizeof (DBT));
memset (&data, 0, sizeof (DBT));
memset (&key, 0, sizeof DBT);
memset (&data, 0, sizeof DBT);
strncpy (buf, user, sizeof buf);
/* strncpy () is lame and does not NULL terminate. */
......
......@@ -154,81 +154,35 @@ pop3d_usage (char *argv0)
RETSIGTYPE
pop3d_signal (int signo)
{
(void)signo;
syslog (LOG_CRIT, "got signal %d", signo);
/* Master process. */
if (!ofile)
{
syslog(LOG_CRIT, "MASTER: exiting on signal");
exit (1); /* abort(); */
}
if (signo == SIGALRM)
pop3d_abquit (ERR_TIMEOUT);
pop3d_abquit (ERR_SIGNAL);
}
/* Gets a line of input from the client */
/* We can also implement PIPELINING by keeping a static buffer.
Implementing this cost an extra allocation with more uglier code.
Is it worth it? How many clients actually use PIPELINING?
*/
/* Gets a line of input from the client, caller should free() */
char *
pop3d_readline (int fd)
pop3d_readline (FILE *fp)
{
static char *buffer = NULL; /* Note: This buffer is never free()d. */
static size_t total = 0;
char *nl;
char *line;
size_t len;
nl = memchr (buffer, '\n', total);
if (!nl)
{
/* Need to refill the buffer. */
do
{
char buf[512];
int nread;
if (timeout)
{
int available;
fd_set rfds;
struct timeval tv;
static char buffer[512];
char *ptr;
FD_ZERO (&rfds);
FD_SET (fd, &rfds);
tv.tv_sec = timeout;
tv.tv_usec = 0;
available = select (fd + 1, &rfds, NULL, NULL, &tv);
if (!available)
pop3d_abquit (ERR_TIMEOUT);
else if (available == -1)
{
if (errno == EINTR)
continue;
pop3d_abquit (ERR_NO_OFILE);
}
}
alarm (timeout);
ptr = fgets (buffer, sizeof (buffer), fp);
alarm (0);
errno = 0;
nread = read (fd, buf, sizeof (buf) - 1);
if (nread < 1)
{
if (errno == EINTR)
continue;
/* We should probably check ferror() too, but if ptr is null we
are done anyway; if (!ptr && ferror(fp)) */
if (!ptr)
pop3d_abquit (ERR_NO_OFILE);
}
buf[nread] = '\0';
buffer = realloc (buffer, (total + nread + 1) * sizeof (*buffer));
if (buffer == NULL)
pop3d_abquit (ERR_NO_MEM);
memcpy (buffer + total, buf, nread + 1); /* copy the null too. */
total += nread;
}
while ((nl = memchr (buffer, '\n', total)) == NULL);
}
nl++;
len = nl - buffer;
line = calloc (len + 1, sizeof (*line));
memcpy (line, buffer, len); /* copy the newline too. */
line[len] = '\0';
total -= len;
memmove (buffer, nl, total);
return line;
/* Caller should not free () this ... should we strdup() then? */
return ptr;
}
......
......@@ -21,7 +21,7 @@ mailbox_t mbox;
size_t timeout;
int state;
char *username;
int ifile;
FILE *ifile;
FILE *ofile;
char *md5shared;
/* Number of child processes. */
......@@ -224,10 +224,12 @@ pop3d_mainloop (int infile, int outfile)
/* Reset hup to exit. */
signal (SIGHUP, pop3d_signal);
/* Timeout alarm. */
signal (SIGALRM, pop3d_signal);
ifile = infile;
ifile = fdopen (infile, "r");
ofile = fdopen (outfile, "w");
if (ofile == NULL)
if (!ofile || !ofile)
pop3d_abquit (ERR_NO_OFILE);
state = AUTHORIZATION;
......@@ -303,6 +305,9 @@ pop3d_mainloop (int infile, int outfile)
pop3d_abquit (ERR_MBOX_SYNC); /* Out of sync, Bail out. */
}
/* Refresh the Lock. */
pop3d_touchlock ();
if (strlen (arg) > POP_MAXCMDLEN || strlen (cmd) > POP_MAXCMDLEN)
status = ERR_TOO_LONG;
else if (strlen (cmd) > 4)
......@@ -361,7 +366,6 @@ pop3d_mainloop (int infile, int outfile)
else
fprintf (ofile, "-ERR unknown error\r\n");
free (buf);
free (cmd);
free (arg);
}
......
......@@ -167,11 +167,10 @@
#endif /* __P */
extern mailbox_t mbox;
extern unsigned int timeout;
extern int state;
extern char *username;
extern int ifile;
extern FILE *ifile;
extern FILE *ofile;
extern char *md5shared;
extern volatile size_t children;
......@@ -202,5 +201,5 @@ extern RETSIGTYPE pop3d_signal __P ((int));
extern RETSIGTYPE pop3d_sigchld __P ((int));
extern void pop3d_daemon_init __P ((void));
extern char *pop3d_apopuser __P ((const char *));
extern char *pop3d_readline __P ((int));
extern char *pop3d_readline __P ((FILE *));
#endif /* _POP3D_H */
......
......@@ -96,7 +96,6 @@ pop3d_user (const char *arg)
buf = pop3d_readline (ifile);
cmd = pop3d_cmd (buf);
tmp = pop3d_args (buf);
free (buf);
if (strlen (tmp) > POP_MAXCMDLEN)
{
......@@ -137,12 +136,13 @@ pop3d_user (const char *arg)
#ifndef USE_LIBPAM
if (pw == NULL || pw->pw_uid < 1)
return ERR_BAD_LOGIN;
if (strcmp (pw->pw_passwd, crypt (pass, pw->pw_passwd)))
if (strcmp (pw->pw_passwd, (char *)crypt (pass, pw->pw_passwd)))
{
#ifdef HAVE_SHADOW_H
struct spwd *spw;
spw = getspnam ((char *)arg);
if (spw == NULL || strcmp (spw->sp_pwdp, crypt (pass, spw->sp_pwdp)))
if (spw == NULL || strcmp (spw->sp_pwdp,
(char *)crypt (pass, spw->sp_pwdp)))
#endif /* HAVE_SHADOW_H */
{
syslog (LOG_INFO, "User '%s': authentication failed", arg);
......@@ -155,6 +155,8 @@ pop3d_user (const char *arg)
int pamerror;
_user = (char *) arg;
_pwd = pass;
/* libpam doesn't log to LOG_MAIL */
closelog ();
pamerror = pam_start ("gnu-pop3d", arg, &PAM_conversation, &pamh);
PAM_ERROR;
pamerror = pam_authenticate (pamh, 0);
......@@ -165,6 +167,7 @@ pop3d_user (const char *arg)
PAM_ERROR;
pam_errlab:
pam_end (pamh, PAM_SUCCESS);
openlog ("gnu-pop3d", LOG_PID, LOG_FACILITY);
if (pamerror != PAM_SUCCESS)
{
syslog (LOG_INFO, "User '%s': authentication failed", _user);
......@@ -176,8 +179,8 @@ pop3d_user (const char *arg)
if (pw != NULL && pw->pw_uid > 1)
setuid (pw->pw_uid);
if ((status = mailbox_create_default (&mbox, arg) != 0)
|| (status = mailbox_open (mbox, MU_STREAM_RDWR) != 0))
if ((status = mailbox_create_default (&mbox, arg)) != 0
|| (status = mailbox_open (mbox, MU_STREAM_RDWR)) != 0)
{
mailbox_destroy (&mbox);
/* For non existent mailbox, we fake. */
......