summaryrefslogtreecommitdiff
path: root/lib/fgetpwent.c
diff options
context:
space:
mode:
authorAlain Magloire <alainm@gnu.org>2001-09-04 01:25:06 +0000
committerAlain Magloire <alainm@gnu.org>2001-09-04 01:25:06 +0000
commit8b262f172f15fb5afa3cb73b7c619650ee5d556f (patch)
tree11ef80382dcedfd6ef6283d8c0728eb7a06dfb43 /lib/fgetpwent.c
parent7191f1dbdd3126049245ae0cd984fed0db7cc6a3 (diff)
downloadmailutils-8b262f172f15fb5afa3cb73b7c619650ee5d556f.tar.gz
mailutils-8b262f172f15fb5afa3cb73b7c619650ee5d556f.tar.bz2
* 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.
Diffstat (limited to 'lib/fgetpwent.c')
-rw-r--r--lib/fgetpwent.c162
1 files changed, 162 insertions, 0 deletions
diff --git a/lib/fgetpwent.c b/lib/fgetpwent.c
new file mode 100644
index 000000000..5b58b8cf3
--- /dev/null
+++ b/lib/fgetpwent.c
@@ -0,0 +1,162 @@
+/* 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

Return to:

Send suggestions and report system problems to the System administrator.