Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
e94e8805
...
e94e8805cc5b73ef8710f58892fbce83d074b084
authored
2001-05-04 03:58:27 +0000
by
Alain Magloire
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Patches from Sergey, se Changelog for details:
2001-04-23 Sergey Poznyakoff
1 parent
e73d4524
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
218 additions
and
144 deletions
ChangeLog
argp/argp-help.c
argp/argp-parse.c
imap4d/login.c
imap4d/rename.c
imap4d/util.c
lib/snprintf.c
lib/snprintf.h
mail/mail.c
mail/mail.h
mail/pipe.c
mail/print.c
mail/top.c
mail/write.c
mailbox/folder_imap.c
pop3d/apop.c
pop3d/extra.c
pop3d/pop3d.c
pop3d/pop3d.h
pop3d/user.c
ChangeLog
View file @
e94e880
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
...
...
argp/argp-help.c
View file @
e94e880
...
...
@@ -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
--
)
...
...
argp/argp-parse.c
View file @
e94e880
...
...
@@ -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
);
...
...
imap4d/login.c
View file @
e94e880
...
...
@@ -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
;
...
...
imap4d/rename.c
View file @
e94e880
...
...
@@ -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
)
...
...
imap4d/util.c
View file @
e94e880
...
...
@@ -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
)
{
...
...
lib/snprintf.c
View file @
e94e880
...
...
@@ -2,21 +2,21 @@
/*
Unix snprintf implementation.
Version 1.3
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Revision History:
1.3:
...
...
@@ -55,7 +55,7 @@ pow_10(int n)
pow_10
(
n
)
int
n
;
#endif
{
{
int
i
;
double
P
;
...
...
@@ -67,7 +67,7 @@ int n;
}
/*
* Find the integral part of the log in base 10
* Find the integral part of the log in base 10
* Note: this not a real log10()
I just need and approximation(integerpart) of x in:
10^x ~= r
...
...
@@ -81,7 +81,7 @@ log_10(double r)
log_10
(
r
)
double
r
;
#endif
{
{
int
i
=
0
;
double
result
=
1
.;
...
...
@@ -110,7 +110,7 @@ integral(real, ip)
double
real
;
double
*
ip
;
#endif
{
{
int
j
;
double
i
,
s
,
p
;
double
real_integral
=
0
.;
...
...
@@ -144,11 +144,11 @@ double * ip;
}
#define PRECISION 1.e-6
/*
/*
* return an ascii representation of the integral part of the number
* and set fract to be an ascii representation of the fraction part
* the container for the fraction and the integral part or staticly
* declare with fix size
* declare with fix size
*/
PRIVATE
char
*
#ifdef __STDC__
...
...
@@ -171,7 +171,7 @@ char ** fract;
int
ch
;
/* taking care of the obvious case: 0.0 */
if
(
number
==
0
.)
{
if
(
number
==
0
.)
{
integral_part
[
0
]
=
'0'
;
integral_part
[
1
]
=
'\0'
;
fraction_part
[
0
]
=
'0'
;
...
...
@@ -183,7 +183,7 @@ char ** fract;
if
((
sign
=
number
)
<
0
.)
{
number
=
-
number
;
digits
--
;
/* sign consume one digit */
}
}
fraction
=
integral
(
number
,
&
ip
);
number
=
ip
;
...
...
@@ -198,11 +198,11 @@ char ** fract;
ch
=
(
int
)((
fp
+
PRECISION
)
*
base
);
/* force to round */
integral_part
[
i
]
=
(
ch
<=
9
)
?
ch
+
'0'
:
ch
+
'a'
-
10
;
if
(
!
isxdigit
(
integral_part
[
i
]))
/* bail out overflow !! */
break
;
break
;
number
=
ip
;
}
}
/* Oh No !! out of bound, ho well fill it up ! */
if
(
number
!=
0
.)
for
(
i
=
0
;
i
<
digits
;
++
i
)
...
...
@@ -216,7 +216,7 @@ char ** fract;
/* reverse every thing */
for
(
i
--
,
j
=
0
;
j
<
i
;
j
++
,
i
--
)
SWAP_INT
(
integral_part
[
i
],
integral_part
[
j
]);
SWAP_INT
(
integral_part
[
i
],
integral_part
[
j
]);
/* the fractionnal part */
for
(
i
=
0
,
fp
=
fraction
;
precision
>
0
&&
i
<
MAX_FRACT
;
i
++
,
precision
--
)
{
...
...
@@ -354,7 +354,7 @@ double d;
((
d
>
0
.
&&
p
->
justify
==
RIGHT
)
?
1
:
0
)
-
((
p
->
space
==
FOUND
)
?
1
:
0
)
-
strlen
(
tmp
)
-
p
->
precision
-
1
;
PAD_RIGHT
(
p
);
PAD_RIGHT
(
p
);
PUT_PLUS
(
d
,
p
);
PUT_SPACE
(
d
,
p
);
while
(
*
tmp
)
{
/* the integral */
...
...
@@ -365,12 +365,12 @@ double d;
PUT_CHAR
(
'.'
,
p
);
/* put the '.' */
if
(
*
p
->
pf
==
'g'
||
*
p
->
pf
==
'G'
)
/* smash the trailing zeros */
for
(
i
=
strlen
(
tmp2
)
-
1
;
i
>=
0
&&
tmp2
[
i
]
==
'0'
;
i
--
)
tmp2
[
i
]
=
'\0'
;
tmp2
[
i
]
=
'\0'
;
for
(;
*
tmp2
;
tmp2
++
)
PUT_CHAR
(
*
tmp2
,
p
);
/* the fraction */
PAD_LEFT
(
p
);
}
}
/* %e %E %g exponent representation */
PRIVATE
void
...
...
@@ -388,12 +388,12 @@ double d;
DEF_PREC
(
p
);
j
=
log_10
(
d
);
d
=
d
/
pow_10
(
j
);
/* get the Mantissa */
d
=
ROUND
(
d
,
p
);
d
=
ROUND
(
d
,
p
);
tmp
=
dtoa
(
d
,
p
->
precision
,
&
tmp2
);
/* 1 for unit, 1 for the '.', 1 for 'e|E',
* 1 for '+|-', 3 for 'exp' */
/* calculate how much padding need */
p
->
width
=
p
->
width
-
p
->
width
=
p
->
width
-
((
d
>
0
.
&&
p
->
justify
==
RIGHT
)
?
1
:
0
)
-
((
p
->
space
==
FOUND
)
?
1
:
0
)
-
p
->
precision
-
7
;
PAD_RIGHT
(
p
);
...
...
@@ -407,7 +407,7 @@ double d;
PUT_CHAR
(
'.'
,
p
);
/* the '.' */
if
(
*
p
->
pf
==
'g'
||
*
p
->
pf
==
'G'
)
/* smash the trailing zeros */
for
(
i
=
strlen
(
tmp2
)
-
1
;
i
>=
0
&&
tmp2
[
i
]
==
'0'
;
i
--
)
tmp2
[
i
]
=
'\0'
;
tmp2
[
i
]
=
'\0'
;
for
(;
*
tmp2
;
tmp2
++
)
PUT_CHAR
(
*
tmp2
,
p
);
/* the fraction */
...
...
@@ -470,7 +470,7 @@ struct DATA * p;
case
'1'
:
case
'2'
:
case
'3'
:
case
'4'
:
case
'5'
:
case
'6'
:
case
'7'
:
case
'8'
:
case
'9'
:
/* gob all the digits */
for
(
i
=
0
;
isdigit
(
*
s
);
i
++
,
s
++
)
for
(
i
=
0
;
isdigit
(
*
s
);
i
++
,
s
++
)
if
(
i
<
MAX_FIELD
/
2
-
1
)
number
[
i
]
=
*
s
;
number
[
i
]
=
'\0'
;
...
...
@@ -524,10 +524,10 @@ va_list args;
case
'f'
:
/* float, double */
STAR_ARGS
(
&
data
);
d
=
va_arg
(
args
,
double
);
floating
(
&
data
,
d
);
floating
(
&
data
,
d
);
state
=
0
;
break
;
case
'g'
:
case
'g'
:
case
'G'
:
STAR_ARGS
(
&
data
);
DEF_PREC
(
&
data
);
...
...
@@ -559,7 +559,7 @@ va_list args;
d
=
va_arg
(
args
,
unsigned
int
);
decimal
(
&
data
,
d
);
state
=
0
;
break
;
break
;
case
'd'
:
/* decimal */
STAR_ARGS
(
&
data
);
if
(
data
.
a_long
==
FOUND
)
...
...
@@ -578,7 +578,7 @@ va_list args;
octal
(
&
data
,
d
);
state
=
0
;
break
;
case
'x'
:
case
'x'
:
case
'X'
:
/* hexadecimal */
STAR_ARGS
(
&
data
);
if
(
data
.
a_long
==
FOUND
)
...
...
@@ -612,11 +612,11 @@ va_list args;
state
=
0
;
break
;
case
'#'
:
case
' '
:
case
'+'
:
case
'*'
:
case
'-'
:
case
'.'
:
case
'0'
:
case
'1'
:
case
'-'
:
case
'.'
:
case
'0'
:
case
'1'
:
case
'2'
:
case
'3'
:
case
'4'
:
case
'5'
:
case
'6'
:
case
'7'
:
case
'8'
:
case
'9'
:
/* initialize width and precision */
for
(
i
=
0
;
isflag
(
*
data
.
pf
);
i
++
,
data
.
pf
++
)
for
(
i
=
0
;
isflag
(
*
data
.
pf
);
i
++
,
data
.
pf
++
)
if
(
i
<
MAX_FIELD
-
1
)
conv_field
[
i
]
=
*
data
.
pf
;
conv_field
[
i
]
=
'\0'
;
...
...
@@ -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
);
...
...
@@ -808,7 +808,7 @@ void main()
printf
(
"abc%n"
,
&
i
);
printf
(
"%d
\n
"
,
i
);
snprintf
(
holder
,
sizeof
holder
,
"abc%n"
,
&
i
);
printf
(
"%s"
,
holder
);
printf
(
"%d
\n\n
"
,
i
);
printf
(
"%%*.*s --> 10.10
\n
"
);
snprintf
(
holder
,
sizeof
holder
,
"%*.*s
\n
"
,
10
,
10
,
BLURB
);
printf
(
"%*.*s
\n
"
,
10
,
10
,
BLURB
);
...
...
@@ -821,7 +821,7 @@ void main()
#define BIG "Hello this is a too big string for the buffer"
/* printf("A buffer to small of 10, trying to put this:\n");*/
printf
(
"<%%>, %s
\n
"
,
BIG
);
printf
(
"<%%>, %s
\n
"
,
BIG
);
i
=
snprintf
(
holder
,
10
,
"%s
\n
"
,
BIG
);
printf
(
"<%s>
\n
"
,
BIG
);
printf
(
"<%s>
\n
"
,
holder
);
...
...
lib/snprintf.h
View file @
e94e880
/*
Unix snprintf implementation.
Version 1.3
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Revision History:
see header of snprintf.c.
...
...
@@ -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>
...
...
@@ -49,7 +49,7 @@ Alain Magloire: alainm@rcsm.ee.mcgill.ca
#include <ctype.h>
/*
/*
* For the FLOATING POINT FORMAT :
* the challenge was finding a way to
* manipulate the Real numbers without having
...
...
@@ -65,24 +65,24 @@ Alain Magloire: alainm@rcsm.ee.mcgill.ca
fraction = b(1)*10^-1 + b(2)*10^-2 + ...
where:
0 <= a(i) => 9
0 <= b(i) => 9
0 <= a(i) => 9
0 <= b(i) => 9
from then it was simple math
*/
/*
* size of the buffer for the integral part
* and the fraction part
* and the fraction part
*/
#define MAX_INT 99 + 1
/* 1 for the null */
#define MAX_FRACT 29 + 1
/*
/*
* numtoa() uses PRIVATE buffers to store the results,
* So this function is not reentrant
*/
#define itoa(n) numtoa(n, 10, 0, (char **)0)
#define itoa(n) numtoa(n, 10, 0, (char **)0)
#define otoa(n) numtoa(n, 8, 0, (char **)0)
#define htoa(n) numtoa(n, 16, 0, (char **)0)
#define dtoa(n, p, f) numtoa(n, 10, p, f)
...
...
@@ -182,7 +182,7 @@ struct DATA {
if ((p)->space == FOUND && (d) > 0.) \
PUT_CHAR(' ', p)
/* pad right */
/* pad right */
#define PAD_RIGHT(p) \
if ((p)->width > 0 && (p)->justify != LEFT) \
for (; (p)->width > 0; (p)->width--) \
...
...
mail/mail.c
View file @
e94e880
...
...
@@ -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"
;
...
...
mail/mail.h
View file @
e94e880
...
...
@@ -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 */
...
...
mail/pipe.c
View file @
e94e880
...
...
@@ -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
;
...
...
mail/print.c
View file @
e94e880
...
...
@@ -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
;
...
...
mail/top.c
View file @
e94e880
...
...
@@ -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
);
...
...
mail/write.c
View file @
e94e880
...
...
@@ -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
;
...
...
mailbox/folder_imap.c
View file @
e94e880
...
...
@@ -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
));
...
...
pop3d/apop.c
View file @
e94e880
...
...
@@ -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. */
...
...
pop3d/extra.c
View file @
e94e880
...
...
@@ -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
;
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
);
}
}
errno
=
0
;
nread
=
read
(
fd
,
buf
,
sizeof
(
buf
)
-
1
);
if
(
nread
<
1
)
{
if
(
errno
==
EINTR
)
continue
;
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
);
}
static
char
buffer
[
512
];
char
*
ptr
;
alarm
(
timeout
);
ptr
=
fgets
(
buffer
,
sizeof
(
buffer
),
fp
);
alarm
(
0
);
/* 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
);
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
;
}
...
...
pop3d/pop3d.c
View file @
e94e880
...
...
@@ -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
);
}
...
...
pop3d/pop3d.h
View file @
e94e880
...
...
@@ -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 */
...
...
pop3d/user.c
View file @
e94e880
...
...
@@ -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. */
...
...
Please
register
or
sign in
to post a comment