Commit 8b262f17 8b262f172f15fb5afa3cb73b7c619650ee5d556f by Alain Magloire

* configure.in: AC_REPLACE_FUNCS(fgetpwent);

	* include/mailutils/parse822.h: Add a prototype for
	parse822_skip_nl().

	* lib/Makefile.am: add fgetpwent.c
	* lib/fgetpwent.c: New file.

	* mail/from.c (mail_from): Use the cover functions
	attribute_is_xxxx() instead of getting the flag.

	* mailbox/attribute.c: Cleanup the mess.
	attribute_set_{read,delete,seen,flagged,answered}.
	attribute_unset_{read,delete,seen,flagged,answered}.
	attribute_is_{read,delete,seen,flagged,answered}
	should be no more then cover functions calling
	attribute_set_flags(), attribute_get_flags() and
	attribute_unset_flags().

	* mailbox/folder_imap.c: MU_ATTRIBUTE_READ, is not
	part of IMAP protocol use \\Seen.
	* mailbox/mbx_imap.c: Remove the hack trying to reconnect,
	it does not work.

	* mailbox/mbx_pop.c(pop_get_messages): Set the new
	functions for the attribute.
	(pop_get_attribute): New functions.
	(pop_set_attribute): New functions.
	(pop_unset_attribute): New functions.
	(pop_attr_flags): Removed.

	* mutil.c (mu_hex2ul): GNU coding std.
	(parse822_time): Do not use tzname as a variable name tzname
	is global variable in libc, better clear away.
	(parse822_date_time): Likewised.

	* pop3d/Makefile.am: add virtual.c
	* pop3d/pop3d.c (main): register getpwnam_ip_virtual,
	getpwnam_host_virtual
	* pop3d/pop3d.h: declare,
	getpwnam_ip_virtual(), getpwnam_host_virtual().
	* pop3d/virtual.c: New file.
1 parent 7191f1db
2001-09-03 Alain Magloire
* configure.in: AC_REPLACE_FUNCS(fgetpwent);
* include/mailutils/parse822.h: Add a prototype for
parse822_skip_nl().
* lib/Makefile.am: add fgetpwent.c
* lib/fgetpwent.c: New file.
* mail/from.c (mail_from): Use the cover functions
attribute_is_xxxx() instead of getting the flag.
* mailbox/attribute.c: Cleanup the mess.
attribute_set_{read,delete,seen,flagged,answered}.
attribute_unset_{read,delete,seen,flagged,answered}.
attribute_is_{read,delete,seen,flagged,answered}
should be no more then cover functions calling
attribute_set_flags(), attribute_get_flags() and
attribute_unset_flags().
* mailbox/folder_imap.c: MU_ATTRIBUTE_READ, is not
part of IMAP protocol use \\Seen.
* mailbox/mbx_imap.c: Remove the hack trying to reconnect,
it does not work.
* mailbox/mbx_pop.c(pop_get_messages): Set the new
functions for the attribute.
(pop_get_attribute): New functions.
(pop_set_attribute): New functions.
(pop_unset_attribute): New functions.
(pop_attr_flags): Removed.
* mutil.c (mu_hex2ul): GNU coding std.
(parse822_time): Do not use tzname as a variable name tzname
is global variable in libc, better clear away.
(parse822_date_time): Likewised.
* pop3d/Makefile.am: add virtual.c
* pop3d/pop3d.c (main): register getpwnam_ip_virtual,
getpwnam_host_virtual
* pop3d/pop3d.h: declare,
getpwnam_ip_virtual(), getpwnam_host_virtual().
* pop3d/virtual.c: New file.
2001-09-02 Alain Magloire
* mailbox/mutil.c (getpwma_virtual): Memory overrun, did not
......
......@@ -113,8 +113,8 @@ AC_FUNC_FNMATCH
if test "$ac_cv_func_fnmatch_works" = "no"; then
: LIBOBJS="$LIBOBJS fnmatch.o"
fi
AC_REPLACE_FUNCS(setenv snprintf strtok_r strncasecmp strcasecmp strsignal \
vasprintf)
AC_REPLACE_FUNCS(fgetpwent setenv snprintf strtok_r strncasecmp strcasecmp \
strsignal vasprintf)
AC_CHECK_FUNCS(mkstemp sigaction sysconf)
dnl Check for libraries
......@@ -243,7 +243,7 @@ fi
dnl Output Makefiles
AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile
m4/Makefile doc/Makefile argp/Makefile lib/Makefile lib/posix/Makefile
mailbox/Makefile imap4d/Makefile mailbox/include/Makefile from/Makefile
m4/Makefile doc/Makefile argp/Makefile lib/Makefile lib/posix/Makefile
mailbox/Makefile imap4d/Makefile mailbox/include/Makefile from/Makefile
mail/Makefile pop3d/Makefile frm/Makefile sieve/Makefile messages/Makefile
scripts/Makefile libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile MySql/Makefile)
......
......@@ -60,6 +60,7 @@ extern int parse822_skip_crlf __P ((const char** p, const char* e));
extern int parse822_skip_lwsp_char __P ((const char** p, const char* e));
extern int parse822_skip_lwsp __P ((const char** p, const char* e));
extern int parse822_skip_comments __P ((const char** p, const char* e));
extern int parse822_skip_nl __P ((const char** p, const char* e));
extern int parse822_digits __P ((const char** p, const char* e, int min, int max, int* digits));
extern int parse822_special __P ((const char** p, const char* e, char c));
......@@ -104,7 +105,7 @@ extern int parse822_field_name __P ((const char** p, const char *e, char**
extern int parse822_day __P ((const char** p, const char* e, int* day));
extern int parse822_date __P ((const char** p, const char* e, int* day, int* mon, int* year));
extern int parse822_time __P ((const char** p, const char* e, int* h, int* m, int* s, int* tz, const char** tzname));
extern int parse822_time __P ((const char** p, const char* e, int* h, int* m, int* s, int* tz, const char** tz_name));
extern int parse822_date_time __P ((const char** p, const char* e, struct tm* tm, mu_timezone* tz));
......
......@@ -7,7 +7,8 @@ libmailutils_a_SOURCES = basename.c getopt.c getopt1.c md5.c getline.c \
xstrdup.c xmalloc.c argcv.c
EXTRA_DIST = alloca.c fnmatch.c setenv.c snprintf.c strchrnul.c strndup.c \
strnlen.c strtok_r.c strsignal.c xstrtol.c vasprintf.c malloc.c realloc.c
strnlen.c strtok_r.c strsignal.c xstrtol.c vasprintf.c malloc.c realloc.c \
fgetpwent.c
noinst_HEADERS = argcv.h error.h fnmatch.h getline.h getopt.h md5.h \
regex.h snprintf.h xalloc.h xstrtol.h
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Library 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 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. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <pwd.h>
#include <string.h>
#include <stdlib.h>
/*
Written by Alain Magloire.
Simple replacement for fgetpwent(), it is not :
- thread safe;
- static buffer was not use since it will limit the size
of the entry. But rather memory is allocated and __never__
release. The memory will grow if need be.
- no support for shadow
- no support for NIS(+)
*/
static char *buffer;
static size_t buflen;
static struct passwd pw;
static char *
parse_line (char *s, char **p)
{
if (*s)
{
char *sep = strchr (s, ':');
if (sep)
{
*sep++ = '\0';
*p = sep;
}
else
*p = s + strlen (s);
}
else
*p = s;
return s;
}
static struct passwd *
getentry (char *s)
{
char *p;
pw.pw_name = parse_line (s, &p);
s = p;
pw.pw_passwd = parse_line (s, &p);
s = p;
pw.pw_uid = strtoul (parse_line (s, &p), NULL, 10);
s = p;
pw.pw_gid = strtoul (parse_line (s, &p), NULL, 10);
s = p;
pw.pw_gecos = parse_line (s, &p);
s = p;
pw.pw_dir = parse_line (s, &p);
s = p;
pw.pw_shell = parse_line (s, &p);
return &pw;
}
struct passwd *
fgetpwent (FILE *fp)
{
size_t pos = 0;
int done = 0;
struct passwd *pw = NULL;
/* Allocate buffer if not yet available. */
/* This buffer will be never free(). */
if (buffer == NULL)
{
buflen = 1024;
buffer = malloc (buflen);
if (buffer == NULL)
return NULL;
}
do
{
if (fgets (buffer + pos, buflen, fp) != NULL)
{
/* Need a full line. */
if (buffer[strlen (buffer) - 1] == '\n')
{
/* reset marker position. */
pos = 0;
/* Nuke trailing newline. */
buffer[strlen (buffer) - 1] = '\0';
/* Skip comments. */
if (buffer[0] != '#')
{
done = 1;
pw = getentry (buffer);
}
}
else
{
/* Line is too long reallocate the buffer. */
char *tmp;
pos = strlen (buffer);
buflen *= 2;
tmp = realloc (buffer, buflen);
if (tmp)
buffer = tmp;
else
done = 1;
}
}
else
done = 1;
} while (!done);
return pw;
}
#ifdef STANDALONE
int
main ()
{
FILE *fp = fopen ("/etc/passwd", "r");
if (fp)
{
struct passwd *pwd;
while ((pwd = fgetpwent (fp)))
{
printf ("--------------------------------------\n");
printf ("name %s\n", pwd->pw_name);
printf ("passwd %s\n", pwd->pw_passwd);
printf ("uid %d\n", pwd->pw_uid);
printf ("gid %d\n", pwd->pw_gid);
printf ("gecos %s\n", pwd->pw_gecos);
printf ("dir %s\n", pwd->pw_dir);
printf ("shell %s\n", pwd->pw_shell);
}
}
return 0;
}
#endif
......@@ -37,7 +37,7 @@ mail_copy0 (int argc, char **argv, int mark)
msgset_t *msglist = NULL, *mp;
int sender = 0;
size_t total_size = 0, total_lines = 0, size;
if (isupper (argv[0][0]))
sender = 1;
else if (argc >= 2)
......@@ -80,9 +80,9 @@ mail_copy0 (int argc, char **argv, int mark)
total_size += size;
message_lines (msg, &size);
total_lines += size;
if (mark)
{
{
attribute_t attr;
message_get_attribute (msg, &attr);
attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
......
......@@ -40,7 +40,7 @@ mail_decode (int argc, char **argv)
{
msgset_t *msgset;
struct decode_closure decode_closure;
if (msgset_parse (argc, argv, &msgset))
return 1;
......@@ -58,10 +58,10 @@ display_message (message_t mesg, msgset_t *msgset,
{
FILE *out;
size_t lines = 0;
if (util_isdeleted (msgset->msg_part[0]))
return 1;
message_lines (mesg, &lines);
if ((util_find_env("crt"))->set && lines > util_getlines ())
out = popen (getenv("PAGER"), "w");
......@@ -82,7 +82,7 @@ display_message (message_t mesg, msgset_t *msgset,
}
return 0;
}
static void
display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
int select_hdr)
......@@ -94,7 +94,7 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
size_t num = 0;
size_t i = 0;
char buffer[512];
message_get_header (mesg, &hdr);
header_get_field_count (hdr, &num);
for (i = 1; i <= num; i++)
......@@ -137,7 +137,7 @@ display_part_header (FILE *out, const msgset_t *msgset,
for (i = 1; i < msgset->npart; i++)
fprintf (out, "]");
fprintf (out, "\n");
fprintf (out, "| Type=%s\n", type);
fprintf (out, "| encoding=%s\n", encoding);
fputc ('+', out);
......@@ -156,7 +156,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
char *type;
char *encoding;
int ismime = 0;
message_get_header (mesg, &hdr);
util_get_content_type (hdr, &type);
get_content_encoding (hdr, &encoding);
......@@ -184,7 +184,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
else if (strncasecmp (type, "message/rfc822", strlen (type)) == 0)
{
message_t submsg = NULL;
if (message_unencapsulate (mesg, &submsg, NULL) == 0)
display_message0 (out, submsg, msgset, select_hdr);
}
......@@ -199,7 +199,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
{
body_t body = NULL;
stream_t b_stream = NULL;
display_part_header (out, msgset, type, encoding);
display_headers (out, mesg, msgset, select_hdr);
......@@ -208,20 +208,20 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
{
stream_t d_stream = NULL;
stream_t stream = NULL;
/* Can we decode. */
if (filter_create(&d_stream, b_stream, encoding,
MU_FILTER_DECODE, MU_STREAM_READ) == 0)
stream = d_stream;
else
stream = b_stream;
print_stream (stream, out);
if (d_stream)
stream_destroy (&d_stream, NULL);
}
}
free (type);
free (encoding);
......
......@@ -50,7 +50,7 @@ mail_delete (int argc, char **argv)
{
message_t msg;
attribute_t attr;
mailbox_get_message (mbox, realcursor, &msg);
message_get_attribute (msg, &attr);
if (!attribute_is_deleted (attr))
......@@ -59,13 +59,13 @@ mail_delete (int argc, char **argv)
realcursor = 1;
}
while (realcursor != here);
cursor = realcursor;
}
if (util_find_env("autoprint")->set)
util_do_command("print");
return rc;
}
......
......@@ -36,7 +36,7 @@ mail_from (int argc, char **argv)
int froml, subjl;
char date[80], st[10];
int cols = util_getcols () - 6;
int flags, cflag;
int cflag;
size_t m_size = 0, m_lines = 0;
const char *p;
struct tm tm;
......@@ -78,7 +78,6 @@ mail_from (int argc, char **argv)
}
message_get_attribute (msg, &attr);
attribute_get_flags (attr, &flags);
if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_MBOXED))
cflag = 'M';
......@@ -86,9 +85,9 @@ mail_from (int argc, char **argv)
cflag = '*';
else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_TAGGED))
cflag = 'T';
else if (flags & MU_ATTRIBUTE_READ)
else if (attribute_is_read (attr))
cflag = 'R';
else if (flags & MU_ATTRIBUTE_SEEN)
else if (attribute_is_seen (attr))
cflag = 'U';
else if (attribute_is_recent(attr))
cflag = 'N';
......
......@@ -27,7 +27,7 @@ mail_hold (int argc, char **argv)
{
message_t msg;
attribute_t attr;
if (argc > 1)
return util_msglist_command (mail_hold, argc, argv, 1);
else
......
......@@ -125,7 +125,7 @@ struct message_set
int *msg_part; /* Array of part numbers: msg_part[0] is the message
number */
};
/* Global variables and constants*/
extern mailbox_t mbox;
extern unsigned int cursor;
......
......@@ -26,7 +26,7 @@ mail_mbox (int argc, char **argv)
{
message_t msg;
attribute_t attr;
if (argc > 1)
return util_msglist_command (mail_mbox, argc, argv, 1);
else
......@@ -42,5 +42,3 @@ mail_mbox (int argc, char **argv)
}
return 0;
}
......
......@@ -28,7 +28,7 @@ struct header_data
char *header;
char *expr;
};
static msgset_t *msgset_select (int (*sel)(), void *closure, int rev,
int max_matches);
static int select_header (message_t msg, void *closure);
......@@ -114,7 +114,7 @@ msg : header REGEXP /* /.../ */
{
struct header_data hd;
hd.header = $1;
hd.expr = $2;
hd.expr = $2;
$$ = msgset_select (select_header, &hd, 0, 0);
if ($1)
free ($1);
......@@ -289,7 +289,7 @@ yylex()
{
char *p = ++cur_p;
int len;
while (*cur_p && *cur_p != '/')
cur_p++;
len = cur_p - p + 1;
......@@ -487,7 +487,7 @@ select_header (message_t msg, void *closure)
header_t hdr;
char *contents;
char *header = hd->header ? hd->header : MU_HEADER_SUBJECT;
message_get_header (msg, &hdr);
if (header_aget_value (hdr, header, &contents) == 0)
{
......
......@@ -40,7 +40,7 @@ mail_print (int argc, char **argv)
size_t n = 0, lines = 0;
FILE *out = ofile;
attribute_t attr;
if (mailbox_get_message (mbox, cursor, &mesg) != 0)
return 1;
......@@ -56,7 +56,7 @@ mail_print (int argc, char **argv)
{
size_t i, num = 0;
char buffer[512];
message_get_header (mesg, &hdr);
header_get_field_count (hdr, &num);
......@@ -95,10 +95,8 @@ mail_print (int argc, char **argv)
message_get_attribute (mesg, &attr);
attribute_set_read (attr);
return 0;
}
return 1;
}
......
......@@ -35,10 +35,10 @@ mail_mbox_close ()
{
url_t url = NULL;
size_t held_count;
if (mail_mbox_commit ())
return 1;
mailbox_save_attributes (mbox);
mailbox_expunge (mbox);
......@@ -63,9 +63,9 @@ mail_mbox_commit ()
int hold = util_find_env ("hold")->set;
url_t url;
int is_user_mbox;
mailbox_get_url (mbox, &url);
is_user_mbox = strcmp (url_to_string (url), getenv("MBOX")) == 0;
is_user_mbox = strcmp (url_to_string (url), getenv("MBOX")) == 0;
{
mailbox_t mb;
......@@ -97,7 +97,7 @@ mail_mbox_commit ()
if (!dest_mbox)
{
char *name = getenv ("MBOX");
if (mailbox_create_default (&dest_mbox, name)
|| mailbox_open (dest_mbox,
MU_STREAM_WRITE | MU_STREAM_CREAT))
......@@ -106,7 +106,7 @@ mail_mbox_commit ()
return 1;
}
}
mailbox_append_message (dest_mbox, msg);
attribute_set_deleted (attr);
saved_count++;
......
......@@ -38,7 +38,7 @@ mail_tag (int argc, char **argv)
{
msgset_t *msgset;
int action = argv[0][0] != 'u';
if (msgset_parse (argc, argv, &msgset))
return 1;
......@@ -47,4 +47,3 @@ mail_tag (int argc, char **argv)
msgset_free (msgset);
return 0;
}
......
......@@ -141,7 +141,7 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor)
{
msgset_t *list = NULL, *mp;
int status = 0;
if (msgset_parse (argc, argv, &list))
return 1;
......@@ -840,7 +840,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
int nparts = 0;
char *type = NULL;
header_t hdr = NULL;
message_get_header (mesg, &hdr);
util_get_content_type (hdr, &type);
if (strncasecmp (type, "message/rfc822", strlen (type)) == 0)
......@@ -852,7 +852,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
}
mesg = submsg;
}
message_get_num_parts (mesg, &nparts);
if (nparts < msgset->msg_part[i])
{
......@@ -860,7 +860,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
msgset->msg_part[i]);
return 1;
}
if (message_get_part (mesg, msgset->msg_part[i], &submsg))
{
util_error ("can't get (sub)part from the message: %d",
......@@ -874,20 +874,20 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
*part = mesg;
return 0;
}
void
util_msgset_iterate (msgset_t *msgset, int (*fun)(), void *closure)
{
for (; msgset; msgset = msgset->next)
{
message_t mesg;
if (mailbox_get_message (mbox, msgset->msg_part[0], &mesg) != 0)
return;
if (util_descend_subparts (mesg, msgset, &mesg) == 0)
(*fun)(mesg, msgset, closure);
}
}
}
int
......
......@@ -31,7 +31,7 @@ mail_visual (int argc, char **argv)
message_t msg = NULL;
attribute_t attr = NULL;
char *file = tempnam(getenv("TMPDIR"), "mu");
util_do_command ("copy %s", file); /* NOTE: copy does not set flags */
util_do_command ("shell %s %s", getenv("VISUAL"), file);
......@@ -42,7 +42,7 @@ mail_visual (int argc, char **argv)
mailbox_get_message (mbox, cursor, &msg);
message_get_attribute (msg, &attr);
attribute_set_read (attr);
return 0;
}
return 1;
......
......@@ -37,7 +37,7 @@ mail_write (int argc, char **argv)
msgset_t *msglist = NULL, *mp;
int sender = 0;
size_t total_size = 0, total_lines = 0, size;
if (isupper (argv[0][0]))
sender = 1;
else if (argc >= 2)
......@@ -73,7 +73,7 @@ mail_write (int argc, char **argv)
msgset_free (msglist);
return 1;
}
for (mp = msglist; mp; mp = mp->next)
{
attribute_t attr;
......@@ -85,7 +85,7 @@ mail_write (int argc, char **argv)
total_size += size;
body_lines (bod, &size);
total_lines += size;
body_get_stream (bod, &stream);
/* should there be a separator? */
while (stream_read(stream, buffer, sizeof (buffer) - 1, off, &n) == 0
......@@ -95,7 +95,7 @@ mail_write (int argc, char **argv)
fprintf (output, "%s", buffer);
off += n;
}
/* mark as saved. */
message_get_attribute (msg, &attr);
......
......@@ -53,7 +53,7 @@ attribute_destroy (attribute_t *pattr, void *owner)
attribute_t attr = *pattr;
if (attr->owner == owner)
free (*pattr);
/* loose the link */
/* Loose the link */
*pattr = NULL;
}
}
......@@ -74,56 +74,56 @@ int
attribute_clear_modified (attribute_t attr)
{
if (!attr)
return 0;
if (attr->_unset_flags)
attr->_unset_flags (attr, MU_ATTRIBUTE_MODIFIED);
attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
return 0;
}
int
attribute_set_modified (attribute_t attr)
{
int status;
if (!attr)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_MODIFIED;
return status;
attr->flags |= MU_ATTRIBUTE_MODIFIED;
return 0;
}
int
attribute_get_flags (attribute_t attr, int *pflags)
{
if (attr == NULL)
if (attr == NULL || pflags == NULL)
return EINVAL;
if (attr->_get_flags)
return attr->_get_flags (attr, pflags);
if (pflags)
*pflags = attr->flags;
*pflags = attr->flags;
return 0;
}
int
attribute_set_flags (attribute_t attr, int flags)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
attr->_set_flags (attr, flags);
attr->flags |= flags;
status = attr->_set_flags (attr, flags);
else
attr->flags |= flags;
if (status == 0)
attribute_set_modified (attr);
return 0;
}
int
attribute_unset_flags (attribute_t attr, int flags)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_unset_flags)
attr->_unset_flags (attr, flags);
attr->flags &= ~flags;
status = attr->_unset_flags (attr, flags);
else
attr->flags &= ~flags;
if (status == 0)
attribute_set_modified (attr);
return 0;
}
......@@ -177,91 +177,45 @@ attribute_set_userflag (attribute_t attr, int flag)
int
attribute_set_seen (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_SEEN | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_SEEN | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_SEEN);
}
int
attribute_set_answered (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_ANSWERED | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_ANSWERED | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_ANSWERED);
}
int
attribute_set_flagged (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_FLAGGED | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_FLAGGED | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_FLAGGED);
}
int
attribute_set_read (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_READ | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_READ | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_READ);
}
int
attribute_set_deleted (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_DELETED | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_DELETED | MU_ATTRIBUTE_MODIFIED;
return 0;
return attribute_set_flags (attr, MU_ATTRIBUTE_DELETED);
}
int
attribute_set_draft (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_set_flags)
status = attr->_set_flags (attr, MU_ATTRIBUTE_DRAFT | MU_ATTRIBUTE_MODIFIED);
attr->flags |= MU_ATTRIBUTE_DRAFT | MU_ATTRIBUTE_MODIFIED;
return status;
return attribute_set_flags (attr, MU_ATTRIBUTE_DRAFT);
}
int
attribute_set_recent (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return EINVAL;
if (attr->_unset_flags)
{
status |= attr->_unset_flags (attr, MU_ATTRIBUTE_READ);
status |= attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
}
if (attr == NULL)
{
attr->flags &= ~MU_ATTRIBUTE_READ;
attr->flags &= ~MU_ATTRIBUTE_SEEN;
}
int status = attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
if (status == 0)
status = attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
return status;
}
......@@ -276,74 +230,68 @@ attribute_is_userflag (attribute_t attr, int flag)
int
attribute_is_seen (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_SEEN;
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_SEEN;
return 0;
}
int
attribute_is_answered (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_ANSWERED;
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_ANSWERED;
return 0;
}
int
attribute_is_flagged (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_FLAGGED;
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_FLAGGED;
return 0;
}
int
attribute_is_read (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_READ;
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_READ;
return 0;
}
int
attribute_is_deleted (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_DELETED;
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_DELETED;
return 0;
}
int
attribute_is_draft (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
return attr->flags & MU_ATTRIBUTE_DRAFT;
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
return flags & MU_ATTRIBUTE_DRAFT;
return 0;
}
int
attribute_is_recent (attribute_t attr)
{
if (attr == NULL)
return 0;
if (attr->_get_flags)
attr->_get_flags (attr, &(attr->flags));
/* something is recent when it is not read and not seen. */
return (attr->flags == 0
|| ! ((attr->flags & MU_ATTRIBUTE_SEEN)
|| (attr->flags & MU_ATTRIBUTE_READ)));
int flags = 0;
if (attribute_get_flags (attr, &flags) == 0)
{
/* something is recent when it is not read and not seen. */
return (flags == 0 || ! ((flags & MU_ATTRIBUTE_SEEN)
|| (flags & MU_ATTRIBUTE_READ)));
}
return 0;
}
int
......@@ -358,105 +306,52 @@ attribute_unset_userflag (attribute_t attr, int flag)
int
attribute_unset_seen (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
attr->flags &= ~MU_ATTRIBUTE_SEEN;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
}
int
attribute_unset_answered (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
attr->flags &= ~MU_ATTRIBUTE_ANSWERED;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
}
int
attribute_unset_flagged (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
attr->flags &= ~MU_ATTRIBUTE_FLAGGED;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
}
int
attribute_unset_read (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_READ);
attr->flags &= ~MU_ATTRIBUTE_READ;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
}
int
attribute_unset_deleted (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_DELETED);
attr->flags &= ~MU_ATTRIBUTE_DELETED;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_DELETED);
}
int
attribute_unset_draft (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
attr->flags &= ~MU_ATTRIBUTE_DRAFT;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
}
int
attribute_unset_recent (attribute_t attr)
{
int status = 0;
if (attr == NULL)
return 0;
if (attr->_unset_flags)
status = attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
attr->flags |= MU_ATTRIBUTE_SEEN;
attribute_set_modified (attr);
return status;
return attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
}
int
attribute_is_equal (attribute_t attr, attribute_t attr2)
{
int status = 0;
if (attr == NULL || attr2 == NULL)
return 0;
if (attr->_get_flags)
status = attr->_get_flags (attr, &(attr->flags));
if (attr2->_get_flags)
status = attr2->_get_flags (attr2, &(attr2->flags));
return attr->flags == attr2->flags;
int flags2 = 0, flags = 0;
attribute_get_flags (attr, &flags);
attribute_get_flags (attr2, &flags2);
return flags == flags;
}
/* Miscellaneous. */
......@@ -550,3 +445,4 @@ flags_to_string (int flags, char *buffer, size_t len, size_t *pn)
*pn = i;
return 0;
}
......
......@@ -1262,7 +1262,10 @@ imap_flags (f_imap_t f_imap, char **ptr)
if (strcasecmp (flag, "\\Seen") == 0)
{
if (msg_imap)
msg_imap->flags |= MU_ATTRIBUTE_SEEN;
{
msg_imap->flags |= MU_ATTRIBUTE_SEEN;
msg_imap->flags |= MU_ATTRIBUTE_READ;
}
else
f_imap->flags |= MU_ATTRIBUTE_SEEN;
}
......@@ -1294,13 +1297,6 @@ imap_flags (f_imap_t f_imap, char **ptr)
else
f_imap->flags |= MU_ATTRIBUTE_DRAFT;
}
else if (strcasecmp (flag, "\\Read") == 0)
{
if (msg_imap)
msg_imap->flags |= MU_ATTRIBUTE_READ;
else
f_imap->flags |= MU_ATTRIBUTE_READ;
}
}
return 0;
}
......
......@@ -31,6 +31,7 @@
#endif
#include <mailutils/mailbox.h>
#include <mailutils/mutil.h>
#include <mailutils/error.h>
#ifndef _PATH_MAILDIR
......
......@@ -500,18 +500,7 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
case IMAP_SELECT:
status = imap_send (f_imap);
if (status != 0)
{
/* HACK!!!!! Force a reconnect here. */
if (status != EAGAIN && status != EINPROGRESS && status != EINTR)
{
CLEAR_STATE (f_imap);
status = folder_open (f_imap->folder, f_imap->folder->flags);
CHECK_EAGAIN (f_imap, status);
return imap_messages_count (mailbox, pnum);
}
return status;
}
CHECK_EAGAIN (f_imap, status);
f_imap->state = IMAP_SELECT_ACK;
case IMAP_SELECT_ACK:
......@@ -521,7 +510,6 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
break;
default:
status = folder_open (f_imap->folder, f_imap->folder->flags);
CHECK_EAGAIN (f_imap, status);
return status;
}
......@@ -1267,9 +1255,9 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen,
if (now == (time_t)-1)
{
struct tm* gmt;
time(&now);
gmt = gmtime(&now);
tm = *gmt;
......@@ -1281,7 +1269,7 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen,
/* FIXME: I don't know what strftime does if the buflen is too
short, or it fails. Assuming that it won't fail, this is my guess
as to the right thing.
I think if the buffer is too short, it will fill it as much
as it can, and nul terminate it. But I'll terminate it anyhow.
*/
......@@ -1290,7 +1278,7 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen,
len = buflen - 1;
buffer[len] = 0;
}
if(plen)
*plen = len;
}
......
......@@ -111,7 +111,9 @@ static int pop_message_fd __P ((stream_t, int *));
static int pop_top __P ((header_t, char *, size_t, off_t, size_t *));
static int pop_retr __P ((pop_message_t, char *, size_t, off_t, size_t *));
static int pop_get_fd __P ((pop_message_t, int *));
static int pop_attr_flags __P ((attribute_t, int *));
static int pop_get_attribute __P ((attribute_t, int *));
static int pop_set_attribute __P ((attribute_t, int));
static int pop_unset_attribute __P ((attribute_t, int));
static int pop_uidl __P ((message_t, char *, size_t, size_t *));
static int pop_uid __P ((message_t, size_t *));
static int fill_buffer __P ((pop_data_t, char *, size_t));
......@@ -140,6 +142,7 @@ struct _pop_message
size_t message_size;
size_t num;
char *uidl; /* Cache the uidl string. */
int attr_flags;
message_t message;
pop_data_t mpd; /* Back pointer. */
};
......@@ -809,7 +812,9 @@ pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
free (mpm);
return status;
}
attribute_set_get_flags (attribute, pop_attr_flags, msg);
attribute_set_get_flags (attribute, pop_get_attribute, msg);
attribute_set_set_flags (attribute, pop_set_attribute, msg);
attribute_set_unset_flags (attribute, pop_unset_attribute, msg);
message_set_attribute (msg, attribute, mpm);
}
......@@ -1214,19 +1219,47 @@ pop_body_lines (body_t body, size_t *plines)
the RETR some go as much as deleting after the TOP, since technicaly
you can download a message via TOP without RET'reiving it. */
static int
pop_attr_flags (attribute_t attr, int *pflags)
pop_get_attribute (attribute_t attr, int *pflags)
{
message_t msg = attribute_get_owner (attr);
pop_message_t mpm = message_get_owner (msg);
char hdr_status[64];
header_t header = NULL;
if (mpm == NULL || pflags == NULL)
return EINVAL;
if (mpm->attr_flags == 0)
{
hdr_status[0] = '\0';
message_get_header (mpm->message, &header);
header_get_value (header, "Status", hdr_status, sizeof hdr_status, NULL);
string_to_flags (hdr_status, &(mpm->attr_flags));
}
*pflags = mpm->attr_flags;
return 0;
}
static int
pop_set_attribute (attribute_t attr, int flags)
{
message_t msg = attribute_get_owner (attr);
pop_message_t mpm = message_get_owner (msg);
if (mpm == NULL)
return EINVAL;
mpm->attr_flags |= flags;
return 0;
}
static int
pop_unset_attribute (attribute_t attr, int flags)
{
message_t msg = attribute_get_owner (attr);
pop_message_t mpm = message_get_owner (msg);
if (mpm == NULL)
return EINVAL;
hdr_status[0] = '\0';
message_get_header (mpm->message, &header);
header_get_value (header, "Status", hdr_status, sizeof (hdr_status), NULL);
string_to_flags (hdr_status, pflags);
mpm->attr_flags &= ~flags;
return 0;
}
......
......@@ -35,7 +35,8 @@
/* convert a sequence of hex characters into an integer */
unsigned long mu_hex2ul(char hex)
unsigned long
mu_hex2ul (char hex)
{
if (hex >= '0' && hex <= '9')
return hex - '0';
......@@ -49,21 +50,22 @@ unsigned long mu_hex2ul(char hex)
return -1;
}
size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
size_t
mu_hexstr2ul (unsigned long *ul, const char *hex, size_t len)
{
size_t r;
*ul = 0;
for (r = 0; r < len; r++)
{
unsigned long v = mu_hex2ul(hex[r]);
{
unsigned long v = mu_hex2ul (hex[r]);
if(v == (unsigned long)-1)
return r;
if (v == (unsigned long)-1)
return r;
*ul = *ul * 16 + v;
}
*ul = *ul * 16 + v;
}
return r;
}
......@@ -83,18 +85,18 @@ mu_tm2time (struct tm *timeptr, mu_timezone* tz)
{
int offset = tz ? tz->utc_offset : 0;
return mktime(timeptr) + mu_utc_offset() - offset;
return mktime (timeptr) + mu_utc_offset () - offset;
}
/* Convert time 0 at UTC to our localtime, that tells us the offset
of our current timezone from UTC. */
time_t
mu_utc_offset(void)
mu_utc_offset (void)
{
time_t t = 0;
struct tm* tm = gmtime(&t);
struct tm* tm = gmtime (&t);
return - mktime(tm);
return - mktime (tm);
}
static const char *months[] =
......@@ -243,7 +245,6 @@ mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
return 0;
}
char *
mu_get_homedir (void)
{
......@@ -252,7 +253,7 @@ mu_get_homedir (void)
{
struct passwd *pwd;
pwd = getpwuid(getuid());
pwd = getpwuid (getuid ());
if (!pwd)
return NULL;
homedir = pwd->pw_dir;
......@@ -369,7 +370,7 @@ getpwnam_virtual (const char *u)
{
struct passwd *pw = NULL;
FILE *pfile;
int i = 0, len = strlen (u), delim = 0;
size_t i = 0, len = strlen (u), delim = 0;
char *filename;
mu_virtual_domain = 0;
......
......@@ -1192,7 +1192,7 @@ int parse822_day(const char** p, const char* e, int* day)
if((e - *p) < 3)
return EPARSE;
for(d = 0; days[d]; d++) {
if(strncasecmp(*p, days[d], 3) == 0) {
*p += 3;
......@@ -1245,7 +1245,7 @@ int parse822_date(const char** p, const char* e, int* day, int* mon, int* year)
if((e - *p) < 3)
return EPARSE;
for(m = 0; mons[m]; m++) {
if(strncasecmp(*p, mons[m], 3) == 0) {
*p += 3;
......@@ -1292,7 +1292,7 @@ int parse822_date(const char** p, const char* e, int* day, int* mon, int* year)
}
int parse822_time(const char** p, const char* e,
int* hour, int* min, int* sec, int* tz, const char** tzname)
int* hour, int* min, int* sec, int* tz, const char** tz_name)
{
/* time = hour zone
* hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59
......@@ -1323,7 +1323,7 @@ int parse822_time(const char** p, const char* e,
{ "MDT", -6 * 60 * 60 },
{ "PST", -8 * 60 * 60 },
{ "PDT", -7 * 60 * 60 },
{ NULL, }
{ NULL, 0 }
};
const char* save = *p;
......@@ -1370,8 +1370,8 @@ int parse822_time(const char** p, const char* e,
break;
}
if(tzs[z].tzname) {
if(tzname)
*tzname = tzs[z].tzname;
if(tz_name)
*tz_name = tzs[z].tzname;
if(tz)
*tz = tzs[z].tz;
......@@ -1449,7 +1449,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
int sec = 0;
int tzoffset = 0;
const char* tzname = 0;
const char* tz_name = 0;
if((rc = parse822_day(p, e, &wday))) {
if(rc != EPARSE)
......@@ -1468,7 +1468,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
*p = save;
return rc;
}
if((rc = parse822_time(p, e, &hour, &min, &sec, &tzoffset, &tzname))) {
if((rc = parse822_time(p, e, &hour, &min, &sec, &tzoffset, &tz_name))) {
*p = save;
return rc;
}
......@@ -1493,14 +1493,14 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
tm->tm_gmtoff = tzoffset;
#endif
#ifdef HAVE_TM_ZONE
tm->tm_zone = tzname;
tm->tm_zone = tz_name;
#endif
}
if(tz)
{
tz->utc_offset = tzoffset;
tz->tz_name = tzname;
tz->tz_name = tz_name;
}
return EOK;
......
......@@ -143,7 +143,7 @@ url_parse (url_t url)
{
int err = 0;
char *n = NULL;
struct _url u = { 0, };
struct _url u = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0, 0};
if (!url || !url->name)
return EINVAL;
......
......@@ -4,6 +4,7 @@ INCLUDES =-I$(srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/include
sbin_PROGRAMS = pop3d
pop3d_SOURCES = apop.c auth.c capa.c dele.c extra.c pop3d.c pop3d.h \
list.c lock.c noop.c quit.c retr.c rset.c stat.c top.c uidl.c user.c signal.c
list.c lock.c noop.c quit.c retr.c rset.c stat.c signal.c top.c uidl.c \
user.c virtual.c
pop3d_LDADD = ../mailbox/libmailbox.la @AUTHLIBS@ ../lib/libmailutils.a
pop3d_LDADD = ../mailbox/libmailbox.la @AUTHLIBS@ ../lib/libmailutils.a
......
......@@ -134,8 +134,10 @@ main (int argc, char **argv)
#endif
#ifdef USE_VIRTUAL_DOMAINS
mu_register_getpwnam (getpwnam_virtual);
mu_register_getpwnam (getpwnam_ip_virtual);
mu_register_getpwnam (getpwnam_host_virtual);
#endif
/* Set the signal handlers. */
signal (SIGINT, pop3d_signal);
signal (SIGQUIT, pop3d_signal);
......@@ -146,7 +148,7 @@ main (int argc, char **argv)
signal (SIGTERM, pop3d_signal);
signal (SIGSTOP, pop3d_signal);
signal (SIGPIPE, pop3d_signal);
signal (SIGABRT, pop3d_signal);
signal (SIGABRT, pop3d_signal);
if (mode == DAEMON)
pop3d_daemon_init ();
......@@ -292,7 +294,7 @@ pop3d_mainloop (int infile, int outfile)
/* Lets boogie. */
fprintf (ofile, "+OK POP3 Ready %s\r\n", md5shared);
while (state != UPDATE)
{
char *buf, *arg, *cmd;
......@@ -399,7 +401,7 @@ pop3d_daemon (unsigned int maxchildren, unsigned int port)
pid_t pid;
int listenfd, connfd;
size_t size;
listenfd = socket (AF_INET, SOCK_STREAM, 0);
if (listenfd == -1)
{
......
......@@ -201,4 +201,7 @@ extern int pop3d_touchlock __P ((void));
extern int pop3d_uidl __P ((const char *));
extern int pop3d_user __P ((const char *));
extern int pop3d_unlock __P ((void));
extern struct passwd * getpwnam_ip_virtual __P ((const char *u));
extern struct passwd * getpwnam_host_virtual __P ((const char *u));
#endif /* _POP3D_H */
......
/* GNU mailutils - a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 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. */
#include "pop3d.h"
#ifdef USE_VIRTUAL_DOMAINS
struct passwd *
getpwnam_ip_virtual (const char *u)
{
struct sockaddr_in addr;
struct passwd *pw = NULL;
int len = sizeof (addr);
if (getsockname (fileno (ifile), (struct sockaddr *)&addr, &len) == 0)
{
char *ip;
char *user;
ip = inet_ntoa (addr.sin_addr);
user = malloc (strlen (ip) + strlen (u) + 2);
if (user)
{
sprintf (user, "%s!%s", u, ip);
pw = getpwnam_virtual (user);
free (user);
}
}
return pw;
}
struct passwd *
getpwnam_host_virtual (const char *u)
{
struct sockaddr_in addr;
struct passwd *pw = NULL;
int len = sizeof (addr);
if (getsockname (fileno (ifile), (struct sockaddr *)&addr, &len) == 0)
{
struct hostent *info = gethostbyaddr ((char *)&addr.sin_addr,
4, AF_INET);
if (info)
{
char *user = malloc (strlen (info->h_name) + strlen (u) + 2);
if (user)
{
sprintf (user, "%s!%s", u, info->h_name);
pw = getpwnam_virtual (user);
free (user);
}
}
}
return pw;
}
#endif