aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2008-12-11 13:25:38 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2008-12-11 13:25:38 +0000
commit5e84ff9fff526bb0653ead7e12954bd06c280c6d (patch)
tree5442636dc7e1df2a0cc589411102f3932c95b601
parenta4b325f89b00386a1b0f809c6b793cb9f2b368c8 (diff)
downloadanubis-5e84ff9fff526bb0653ead7e12954bd06c280c6d.tar.gz
anubis-5e84ff9fff526bb0653ead7e12954bd06c280c6d.tar.bz2
Fix option handling, memory leaks and fixed buffer size bugs.
* src/Makefile.am (anubisadm_SOURCES): Add new files. (anubisusr_SOURCES): Add new files. * src/anubisadm.h: New file. * src/adm.opt: New file. * src/anubisusr.h: New file. * src/usr.opt: New file. * src/anubisadm.c: Remove command line option parsing. See adm.opt. * src/anubisusr.c: Remove command line option parsing. See usr.opt. (smtp_get_reply): Use stream_getline, this fixes buffer size problems. * src/env.opt: Fix argument quoting. * src/errs.c (hostname_error): Argument is const. * src/gdbm.c, src/gpg.c, src/guile.c, src/proclist.c, src/transmode.c: Minor change. * src/getopt.m4: Import from Dico. * src/headers.h (stream_getline): New prototype. (hostname_error): Argument is const. * src/main.c (copyright): Remove. (xalloc_die): Call abort to pacify gcc. * src/net.c (recvline): Rewrite using stream_getline. This also fixes memory leak. * src/stream.c (stream_readline): Do not insert \r before \n. This is impossible to do correctly without a proper buffering scheme. (stream_getline): New function. * src/tunnel.c: Remove CRLF after a call to recvline. (transfer_command): Compensate for this.
-rw-r--r--ChangeLog30
-rw-r--r--lib/.cvsignore7
-rw-r--r--m4/.cvsignore4
-rw-r--r--src/.cvsignore2
-rw-r--r--src/Makefile.am6
-rw-r--r--src/adm.opt106
-rw-r--r--src/anubisadm.c150
-rw-r--r--src/anubisadm.h41
-rw-r--r--src/anubisusr.c114
-rw-r--r--src/anubisusr.h45
-rw-r--r--src/env.opt2
-rw-r--r--src/errs.c4
-rw-r--r--src/gdbm.c6
-rw-r--r--src/getopt.m4171
-rw-r--r--src/gpg.c6
-rw-r--r--src/guile.c14
-rw-r--r--src/headers.h16
-rw-r--r--src/main.c3
-rw-r--r--src/net.c37
-rw-r--r--src/proclist.c4
-rw-r--r--src/stream.c41
-rw-r--r--src/transmode.c2
-rw-r--r--src/tunnel.c25
-rw-r--r--src/usr.opt70
24 files changed, 546 insertions, 360 deletions
diff --git a/ChangeLog b/ChangeLog
index 93b4cda..a07f0f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2008-12-11 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ * src/Makefile.am (anubisadm_SOURCES): Add new files.
+ (anubisusr_SOURCES): Add new files.
+ * src/anubisadm.h: New file.
+ * src/adm.opt: New file.
+ * src/anubisusr.h: New file.
+ * src/usr.opt: New file.
+ * src/anubisadm.c: Remove command line option parsing. See adm.opt.
+ * src/anubisusr.c: Remove command line option parsing. See
+ usr.opt.
+ (smtp_get_reply): Use stream_getline, this fixes buffer size
+ problems.
+ * src/env.opt: Fix argument quoting.
+ * src/errs.c (hostname_error): Argument is const.
+ * src/gdbm.c, src/gpg.c, src/guile.c, src/proclist.c,
+ src/transmode.c: Minor change.
+ * src/getopt.m4: Import from Dico.
+ * src/headers.h (stream_getline): New prototype.
+ (hostname_error): Argument is const.
+ * src/main.c (copyright): Remove.
+ (xalloc_die): Call abort to pacify gcc.
+ * src/net.c (recvline): Rewrite using stream_getline. This also fixes
+ memory leak.
+ * src/stream.c (stream_readline): Do not insert \r before \n. This
+ is impossible to do correctly without a proper buffering scheme.
+ (stream_getline): New function.
+ * src/tunnel.c: Remove CRLF after a call to recvline.
+ (transfer_command): Compensate for this.
+
2008-12-09 Wojciech Polak <polak@gnu.org>
* configure.ac: Use default CFLAGS.
diff --git a/lib/.cvsignore b/lib/.cvsignore
index 4f0ac07..628abc5 100644
--- a/lib/.cvsignore
+++ b/lib/.cvsignore
@@ -1,5 +1,7 @@
alloca.h
alloca.in.h
+errno.h
+errno.in.h
error.c
error.h
exitfail.c
@@ -18,6 +20,7 @@ gettext.h
gnulib.mk
intprops.h
lseek.c
+malloc.c
malloca.c
malloca.h
malloca.valgrind
@@ -30,13 +33,17 @@ stdbool.in.h
stdint.h
stdint.in.h
stdio-impl.h
+stdio-write.c
stdio.h
stdio.in.h
stdlib.h
stdlib.in.h
+strdup.c
strerror.c
string.h
string.in.h
+sysexits.h
+sysexits.in.h
unistd.h
unistd.in.h
wchar.h
diff --git a/m4/.cvsignore b/m4/.cvsignore
index 0942c7d..7050797 100644
--- a/m4/.cvsignore
+++ b/m4/.cvsignore
@@ -6,6 +6,7 @@ codeset.m4
eealloc.m4
environ.m4
eoverflow.m4
+errno_h.m4
error.m4
exitfail.m4
extensions.m4
@@ -62,8 +63,11 @@ stdint_h.m4
stdint_h_gl.m4
stdio_h.m4
stdlib_h.m4
+strdup.m4
strerror.m4
string_h.m4
+sysexits.m4
+threadlib.m4
uintmax_t.m4
uintmax_t_gl.m4
ulonglong.m4
diff --git a/src/.cvsignore b/src/.cvsignore
index ea12e2d..0979bfa 100644
--- a/src/.cvsignore
+++ b/src/.cvsignore
@@ -10,3 +10,5 @@ y.output
rcfile-lex.c
rcfile-gram.c
rcfile-gram.h
+usr.c
+adm.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 69de1a6..81598a6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,7 +2,7 @@
## src/Makefile.am
##
## This file is part of GNU Anubis.
-## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 The Anubis Team.
+## Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008 The Anubis Team.
##
## GNU Anubis is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the
@@ -63,9 +63,9 @@ anubis_SOURCES = \
tunnel.c \
xdatabase.c
-anubisadm_SOURCES = anubisadm.c
+anubisadm_SOURCES = anubisadm.c anubisadm.h adm.c
anubisadm_LDADD = ./libanubisdb.a $(top_builddir)/lib/libanubis.a @LIBINTL@
-anubisusr_SOURCES = anubisusr.c
+anubisusr_SOURCES = anubisusr.c anubisusr.h usr.c
anubisusr_LDADD = ./libanubisdb.a $(top_builddir)/lib/libanubis.a @LIBINTL@ @LIBGNUTLS_LIBS@ @GSASL_LIBS@
libanubisdb_a_SOURCES = \
diff --git a/src/adm.opt b/src/adm.opt
new file mode 100644
index 0000000..d955492
--- /dev/null
+++ b/src/adm.opt
@@ -0,0 +1,106 @@
+/* -*- c -*-
+ This file is part of GNU Anubis.
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008 The Anubis Team.
+
+ GNU Anubis 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 3 of the License, or
+ (at your option) any later version.
+
+ GNU Anubis 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 GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <anubisadm.h>
+
+OPTIONS_BEGIN(gnu,"anubisadm",
+ [<Interface for GNU Anubis database administration.>],
+ URL,
+ [<EXAMPLES:\n\n
+
+ 1. Create the GDBM database from a plaintext file:\n\n
+ example$ anubisadm --create gdbm:/etc/anubis.db < plaintext\n\n
+ 2. Add SMTP authid "test" with password "guessme" and map it
+ to the system account "gray":\n\n
+ example$ anubisadm --add --authid test --password guessme
+ --user gray gdbm:/etc/anubis.db\n\n
+ 3. List the database:\n\n
+ example$ anubisadm --list gdbm:/etc/anubis.db\n\n
+ 4. List only the record with authid "test":\n\n
+ example$ anubisadm --list --authid test gdbm:/etc/anubis.db
+ \n\n>])
+
+GROUP([<Administration commands:>])
+OPTION(create,c,,
+ Creates the database.)
+BEGIN
+ *operation = op_create;
+END
+
+OPTION(list,l,,
+ List contents of existing database.)
+BEGIN
+ *operation = op_list;
+END
+
+OPTION(add,a,,
+ Add a new record.)
+BEGIN
+ *operation = op_add;
+END
+
+OPTION(modify,m,,
+ Modify existing record.)
+BEGIN
+ *operation = op_modify;
+END
+
+OPTION(remove,r,,
+ Remove existing record.)
+BEGIN
+ rcfile = optarg;
+END
+
+GROUP(Options:)
+
+OPTION(authid,i,STRING,
+ [<Specify the authid to operate upon. This option
+ is mandatory with --add, --modify and --remove.
+ It is optional when used with --list.>])
+BEGIN
+ authid = optarg;
+END
+
+OPTION(password,p,STRING,
+ [<Specify the password for the authid. Mandatory
+ with --add, --modify and --remove.>])
+BEGIN
+ password = optarg;
+END
+
+OPTION(user,u,STRING,
+ [<Specify the system user name corresponding to
+ the given authid. Optional for --add, --modify and --remove.>])
+BEGIN
+ username = optarg;
+END
+
+OPTION(rcfile,f,STRING,
+ [<Specify the rc file to be used for this authid.
+ Optional for --add, --modify and --remove.>])
+BEGIN
+ rcfile = optarg;
+END
+
+OPTIONS_END
+
+void
+adm_get_options (int argc, char *argv[], operation_fp *operation, int *index)
+{
+ GETOPT(argc, argv, index);
+}
+
diff --git a/src/anubisadm.c b/src/anubisadm.c
index ac36821..e9c273d 100644
--- a/src/anubisadm.c
+++ b/src/anubisadm.c
@@ -1,6 +1,6 @@
/*
This file is part of GNU Anubis
- Copyright (C) 2004, 2007 The Anubis Team.
+ Copyright (C) 2004, 2007, 2008 The Anubis Team.
GNU Anubis is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -16,34 +16,7 @@
with GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include "headers.h"
-#include "extern.h"
-#include "getopt.h"
-
-#define OPT_VERSION 257
-#define OPT_HELP 258
-
-static struct option option[] = {
- {"create", no_argument, 0, 'c'},
- {"list", no_argument, 0, 'l'},
- {"add", no_argument, 0, 'a'},
- {"remove", no_argument, 0, 'r'},
- {"modify", no_argument, 0, 'm'},
- {"authid", required_argument, 0, 'i'},
- {"user", required_argument, 0, 'u'},
- {"rcfile", required_argument, 0, 'f'},
- {"password", optional_argument, 0, 'p'},
-
- {"version", no_argument, 0, OPT_VERSION},
- {"help", no_argument, 0, OPT_HELP},
- {NULL, 0, 0, 0}
-};
-
-typedef int (*operation_fp) (int, char **);
+#include "anubisadm.h"
char *progname;
char *authid;
@@ -110,7 +83,7 @@ op_create (int argc, char **argv)
size_t n = 0;
size_t line = 0;
void *db;
- int rc;
+ int rc = 0;
if (opendb (&db, argc, argv, anubis_db_rdwr))
return 1;
@@ -326,7 +299,7 @@ int
op_remove (int argc, char **argv)
{
void *db;
- int rc;
+ int rc = 0;
if (!authid)
{
@@ -347,7 +320,8 @@ op_remove (int argc, char **argv)
case ANUBIS_DB_FAIL:
error (_("database error: %s"), anubis_db_strerror (db));
rc = 1;
-
+ break;
+
case ANUBIS_DB_SUCCESS:
rc = 0;
}
@@ -362,61 +336,10 @@ op_modify (int argc, char **argv)
_("Record not found. Use --add to create it."));
}
-void
-print_help (void)
-{
- puts (_("anubisadm -- Interface for GNU Anubis database administration."));
- puts (_("Usage: anubisadm [COMMAND] [OPTIONS] URL"));
-
- puts (_("\nCOMMAND is one of\n"));
- puts (_(" -c, --create Creates the database."));
- puts (_
- (" -l, --list List the contents of an existing database."));
- puts (_(" -a, --add Add a new record."));
- puts (_(" -m, --modify Modify existing record."));
- puts (_(" -r, --remove Remove existing record."));
- puts (_
- (" --version Display program version number and exit."));
- puts (_(" --help Display this help screen and exit."));
-
- puts (_("\nOPTION is one or more of\n"));
- puts (_
- (" -i, --authid=STRING Specify the authid to operate upon. This option\n"
- " is mandatory with --add, --modify and --remove.\n"
- " It is optional when used with --list."));
- puts (_
- (" -p, --password=STRING Specify the password for the authid. Mandatory\n"
- " with --add, --modify and --remove."));
- puts (_
- (" -u, --user=STRING Specify the system user name corresponding to\n"
- " the given authid. Optional for --add, --modify\n"
- " and --remove."));
- puts (_
- (" -f, --rcfile=STRING Specify the rc file to be used for this authid.\n"
- " Optional for --add, --modify and --remove."));
-
- puts (_("\nEXAMPLES\n"));
- puts (_("1. Create the GDBM database from a plaintext file:\n\n"
- "example$ anubisadm --create gdbm:/etc/anubis.db < plaintext\n"));
-
- puts (_("2. Add SMTP authid \"test\" with password \"guessme\" and map it\n"
- "to the system account \"gray\":\n\n"
- "example$ anubisadm --add --authid test --password guessme \\\n"
- " --user gray gdbm:/etc/anubis.db\n"));
-
- puts (_("3. List the entire database contents:\n\n"
- "example$ anubisadm --list gdbm:/etc/anubis.db\n"));
-
- puts (_("4. List only the record with authid \"test\":\n\n"
- "example$ anubisadm --list --authid test gdbm:/etc/anubis.db\n"));
-
- printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
-}
-
int
main (int argc, char **argv)
{
- int c;
+ int index;
operation_fp operation = op_usage;
/* save the program name */
@@ -439,63 +362,8 @@ main (int argc, char **argv)
pgsql_db_init ();
# endif
- while ((c = getopt_long (argc, argv, "clarmi:u:f:p:?",
- option, NULL)) != EOF)
- {
- switch (c)
- {
- case OPT_VERSION:
- printf ("%s\n", PACKAGE_STRING);
- exit (0);
- break;
-
- case OPT_HELP:
- print_help ();
- exit (0);
- break;
-
- case 'c':
- operation = op_create;
- break;
-
- case 'l':
- operation = op_list;
- break;
-
- case 'a':
- operation = op_add;
- break;
-
- case 'r':
- operation = op_remove;
- break;
-
- case 'm':
- operation = op_modify;
- break;
-
- case 'i':
- authid = optarg;
- break;
-
- case 'u':
- username = optarg;
- break;
-
- case 'f':
- rcfile = optarg;
- break;
-
- case 'p':
- password = optarg;
- break;
-
- default:
- return 1;
- }
- }
-
- return operation (argc - optind, argv + optind);
+ adm_get_options (argc, argv, &operation, &index);
+ return operation (argc - index, argv + index);
}
/* EOF */
diff --git a/src/anubisadm.h b/src/anubisadm.h
new file mode 100644
index 0000000..fc68dc6
--- /dev/null
+++ b/src/anubisadm.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of GNU Anubis
+ Copyright (C) 2004, 2007 The Anubis Team.
+
+ GNU Anubis 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 3 of the License, or (at your
+ option) any later version.
+
+ GNU Anubis 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 GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "headers.h"
+#include "extern.h"
+#include "getopt.h"
+
+typedef int (*operation_fp) (int, char **);
+
+char *authid;
+char *username;
+char *rcfile;
+char *password;
+
+int op_create (int argc, char **argv);
+int op_list (int argc, char **argv);
+int op_add (int argc, char **argv);
+int op_modify (int argc, char **argv);
+int op_remove (int argc, char **argv);
+
+void adm_get_options (int argc, char *argv[],
+ operation_fp *operation, int *index);
diff --git a/src/anubisusr.c b/src/anubisusr.c
index b18527f..b605aa5 100644
--- a/src/anubisusr.c
+++ b/src/anubisusr.c
@@ -1,7 +1,7 @@
/*
anubisusr.c
- Copyright (C) 2004, 2005, 2007 The Anubis Team.
+ Copyright (C) 2004, 2005, 2007, 2008 The Anubis Team.
GNU Anubis is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -17,23 +17,7 @@
with GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "headers.h"
-#include "extern.h"
-#include "rcfile.h"
-#include <gsasl.h>
-#include "getopt.h"
-
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
-
-#if defined(USE_GNUTLS) && defined(HAVE_GNUTLS_GNUTLS_H)
-# include <gnutls/gnutls.h>
-# define HAVE_TLS
-#endif /* USE_GNUTLS and HAVE_GNUTLS_GNUTLS_H */
+#include <anubisusr.h>
#ifdef HAVE_TLS
char *tls_cafile;
@@ -324,7 +308,8 @@ send_line (char *buf)
int
smtp_get_reply (struct smtp_reply *repl)
{
- char buf[LINEBUFFER + 1];
+ char *buf = NULL;
+ size_t bufsize = 0;
char *p;
int i;
int cont = 0;
@@ -333,7 +318,7 @@ smtp_get_reply (struct smtp_reply *repl)
do
{
size_t n;
- int rc = stream_readline (iostream, buf, sizeof buf, &n);
+ int rc = stream_getline (iostream, &buf, &bufsize, &n);
if (rc)
{
@@ -382,6 +367,7 @@ smtp_get_reply (struct smtp_reply *repl)
}
}
while (cont || *p == '-');
+ free (buf);
obstack_1grow (&input_stk, 0);
repl->base = obstack_finish (&input_stk);
@@ -1152,47 +1138,6 @@ synch (void)
}
-/* Main */
-#define OPT_VERSION 257
-#define OPT_HELP 258
-
-static struct option gnu_options[] = {
- {"verbose", no_argument, 0, 'v'},
- {"version", no_argument, 0, OPT_VERSION},
- {"help", no_argument, 0, OPT_HELP},
- {"file", required_argument, 0, 'f'},
- {"netrc", required_argument, 0, 'n'},
-#ifdef HAVE_TLS
- {"disable-tls", no_argument, 0, 'd'},
- {"tls-cafile", required_argument, 0, 'C'},
-#endif
- {"mechanism", required_argument, 0, 'm'},
- {0, 0, 0, 0}
-};
-
-void
-help (void)
-{
- puts (_("anubisusr -- Synchronize local and remote copies of the user's RC file"));
- puts (_("Usage: anubisusr [OPTIONS] [URL]"));
- puts (_("OPTIONS are:"));
-#ifdef HAVE_TLS
- puts (_(" -d, --disable-tls Disable TLS encryption"));
- puts (_(" -C, --tls-cafile FILE Use given CA file"));
-#endif
- puts (_(" -f, --file FILE Set user configuration file name"));
- puts (_(" -m, --mechanism MECH Restrict allowed SASL mechanisms"));
- puts (_(" -n, --netrc FILE Set .netrc file name"));
- puts (_(" -v, --verbose Verbose output. Multiple options\n"
- " increase the verbosity. Maximum is\n"
- " 3"));
- puts ("");
- puts (_(" --version Display program version"));
- puts (_(" --help Display this help list"));
- printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
- exit (0);
-}
-
#define NETRC_NAME ".netrc"
void
read_netrc (void)
@@ -1222,56 +1167,15 @@ int
main (int argc, char **argv)
{
int c;
-
+ int index;
+
progname = strrchr (argv[0], '/');
if (!progname)
progname = argv[0];
else
progname++;
- while ((c = getopt_long (argc, argv, "dC:f:n:m:v", gnu_options, NULL)) != EOF)
- {
- switch (c)
- {
-#ifdef HAVE_TLS
- case 'd':
- enable_tls = 0;
- break;
-
- case 'C':
- tls_cafile = optarg;
- break;
-
-#endif
- case 'f':
- rcfile_name = optarg;
- break;
-
- case 'n':
- netrc_name = optarg;
- break;
-
- case 'm':
- add_mech (optarg);
- break;
-
- case 'v':
- verbose++;
- break;
-
- case OPT_VERSION:
- printf ("anubisusr (%s)\n", PACKAGE_STRING);
- exit (0);
-
- case OPT_HELP:
- help ();
- break;
-
- default:
- fprintf (stderr, "%s: unknown option -%c\n", progname, optopt);
- exit (1);
- }
- }
+ usr_get_options (argc, argv, &index);
argc -= optind;
argv += optind;
diff --git a/src/anubisusr.h b/src/anubisusr.h
new file mode 100644
index 0000000..e2fc716
--- /dev/null
+++ b/src/anubisusr.h
@@ -0,0 +1,45 @@
+/*
+ anubisusr.h
+
+ Copyright (C) 2004, 2005, 2007, 2008 The Anubis Team.
+
+ GNU Anubis 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 3 of the License, or (at your
+ option) any later version.
+
+ GNU Anubis 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 GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include "headers.h"
+#include "extern.h"
+#include "rcfile.h"
+#include <gsasl.h>
+#include "getopt.h"
+
+#define obstack_chunk_alloc malloc
+#define obstack_chunk_free free
+#include <obstack.h>
+
+#if defined(USE_GNUTLS) && defined(HAVE_GNUTLS_GNUTLS_H)
+# include <gnutls/gnutls.h>
+# define HAVE_TLS
+#endif /* USE_GNUTLS and HAVE_GNUTLS_GNUTLS_H */
+
+extern char *tls_cafile;
+extern int enable_tls;
+extern char *rcfile_name;
+extern char *netrc_name;
+extern int verbose;
+
+void add_mech (char *arg);
+void usr_get_options (int argc, char *argv[], int *index);
+
diff --git a/src/env.opt b/src/env.opt
index 33bdbd4..83c25d7 100644
--- a/src/env.opt
+++ b/src/env.opt
@@ -125,7 +125,7 @@ BEGIN
topt |= T_NORC;
END
-OPTION(check-config, c, [DEBUG-LEVEL],
+OPTION(check-config, c, DEBUG-LEVEL,
Run the configuration file syntax checker)
BEGIN
rc_set_debug_level (optarg);
diff --git a/src/errs.c b/src/errs.c
index 991e2bd..799c151 100644
--- a/src/errs.c
+++ b/src/errs.c
@@ -2,7 +2,7 @@
errs.c
This file is part of GNU Anubis.
- Copyright (C) 2001, 2002, 2003, 2004, 2007 The Anubis Team.
+ Copyright (C) 2001, 2002, 2003, 2004, 2007, 2008 The Anubis Team.
GNU Anubis is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -95,7 +95,7 @@ socket_error (const char *msg)
}
void
-hostname_error (char *host)
+hostname_error (const char *host)
{
if (h_errno == 0)
return;
diff --git a/src/gdbm.c b/src/gdbm.c
index 960c55b..3483beb 100644
--- a/src/gdbm.c
+++ b/src/gdbm.c
@@ -2,7 +2,7 @@
gdbm.c
This file is part of GNU Anubis.
- Copyright (C) 2003, 2004, 2007 The Anubis Team.
+ Copyright (C) 2003, 2004, 2007, 2008 The Anubis Team.
GNU Anubis is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
@@ -48,6 +48,10 @@ gdbm_db_open (void **dp, ANUBIS_URL * url, enum anubis_db_mode mode,
case anubis_db_rdwr:
flags = GDBM_WRCREAT;
+ break;
+
+ default:
+ flags = 0;
}
path = anubis_url_full_path (url);
diff --git a/src/getopt.m4 b/src/getopt.m4
index aef2d0d..4c78394 100644
--- a/src/getopt.m4
+++ b/src/getopt.m4
@@ -1,5 +1,5 @@
dnl This file is part of GNU Anubis.
-dnl Copyright (C) 2007 Sergey Poznyakoff.
+dnl Copyright (C) 2007, 2008 The Anubis Team.
dnl
dnl GNU Anubis is free software; you can redistribute it and/or modify it
dnl under the terms of the GNU General Public License as published by the
@@ -13,9 +13,7 @@ dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License along
dnl with GNU Anubis. If not, see <http://www.gnu.org/licenses/>.
-dnl
-dnl GNU Anubis is released under the GPL with the additional exemption that
-dnl compiling, linking, and/or using OpenSSL is allowed.
+dnl
divert(-1)
changequote([<,>])
changecom(/*,*/)
@@ -55,9 +53,14 @@ dnl of preceding and following whitespace by a single space character, remove
dnl leading whitespace, and escape double-quotes.
dnl
define([<prep>],
- [<escape(flushleft(patsubst([<$1>],[<[ ]*
+[<escape(flushleft(patsubst([<$1>],[<[ ]*
+[ ]*>],[< >])))>])
+define([<newline>],
+[<patsubst([<concat($*)>],[<\\n>],[<\n>])>])
+
+define([<mprep>],[<newline(prep($1))>])
+
dnl SHORT_OPTS
dnl Accumulator for the 3rd argument of getopt_long
dnl
@@ -71,6 +74,28 @@ divert(3)
{ NULL, NULL, 0, N_("prep([<$1>])") },
divert(-1)>])
+define([<__GATHER_OPTIONS>],[<
+define([<KEY>],ifelse([<$2>],,[<OPTION_>]upcase(patsubst($1,-,_)),'$2'))
+ifelse([<$2>],,[<
+divert(1)
+ KEY,
+divert(-1)
+>])
+define([<SELECTOR>],ifdef([<SELECTOR>],SELECTOR) case KEY:)
+ifelse([<$1>],,,[<
+divert(2)
+ { "$1", ARGTYPE, 0, KEY },
+divert(-1)>])
+dnl
+define([<SHORT_OPTS>],SHORT_OPTS[<>]dnl
+ifelse([<$2>],,,$2[<>]ifelse(ARGTYPE,[<no_argument>],,ARGTYPE,[<required_argument>],:,ARGTYPE,[<optional_argument>],::)))
+dnl
+ifelse([<$1>],,,dnl
+[<define([<LONG_TAG>],ifelse(LONG_TAG,,[<--$1>],[<LONG_TAG; --$1>]))>])
+ifelse([<$2>],,,dnl
+[<define([<SHORT_TAG>],ifelse(SHORT_TAG,,[<-$2>],[<SHORT_TAG; -$2>]))>])
+>])
+
dnl OPTION(long-opt, short-opt, [arg], [descr])
dnl Introduce a command line option. Arguments:
dnl long-opt Long option.
@@ -89,39 +114,46 @@ dnl If descr is not given the option will not appear in the --help and
dnl --usage outputs.
dnl
define([<OPTION>],[<
-define([<KEY>],ifelse([<$2>],,[<OPTION_>]upcase(patsubst($1,-,_)),'$2'))
-ifelse([<$2>],,[<
-divert(1)
- KEY,
-divert(-1)
->])
-define([<SELECTOR>],ifdef([<SELECTOR>],SELECTOR) case KEY:)
+pushdef([<LONG_TAG>])
+pushdef([<SHORT_TAG>])
+pushdef([<ARGNAME>],[<$3>])
+pushdef([<DOCSTRING>],[<prep([<$4>])>])
pushdef([<ARGTYPE>],[<ifelse([<$3>],,[<no_argument>],dnl
patsubst([<$3>],[<\[.*\]>]),,[<optional_argument>],dnl
[<required_argument>])>])
-ifelse([<$1>],,,[<
-divert(2)
- { "$1", ARGTYPE, 0, KEY },
-divert(-1)>])
-define([<SHORT_OPTS>],SHORT_OPTS[<>]dnl
-ifelse([<$2>],,,$2[<>]ifelse(ARGTYPE,[<no_argument>],,ARGTYPE,[<required_argument>],:,ARGTYPE,[<optional_argument>],::)))
-pushdef([<TAG>],[<ifelse([<$2>],,,-[<$2[<>]ifelse([<$1>],,,[<, >])>])dnl
-ifelse([<$1>],,,[<--$1>])>])
-ifelse([<$4>],,,[<
-divert(3)
- { "TAG", ifelse([<$3>],,[<NULL, 0>],
-[<ifelse(ARGTYPE,[<optional_argument>],
-[<patsubst([<$3>],[<\[\(.*\)\]>],[<N_("\1"), 1>])>],[<N_("$3"), 0>])>]), N_("prep([<$4>])") },
-divert(-1)>])
-popdef([<ARGTYPE>])
-popdef([<TAG>])>])
+__GATHER_OPTIONS($@)
+>])
+
+dnl ALIAS(long-opt, short-opt)
+dnl Declare aliases for the previous OPTION statement.
+dnl long-opt Long option.
+dnl short-opt Short option (a single char)
+dnl (At least one of long-opt or short-opt must be present)
+dnl An OPTION statement may be followed by any number of ALIAS statements.
+dnl
+define([<ALIAS>],[<
+__GATHER_OPTIONS($1,$2)
+>])
dnl BEGIN
dnl Start an action associated with the declared option. Must follow OPTION
-dnl statement.
+dnl statement, with optional ALIAS statements in between.
dnl
define([<BEGIN>],[<
+ifelse([<DOCSTRING>],,,[<
+divert(3)
+ { "translit(dnl
+ifelse(SHORT_TAG,,LONG_TAG,[<SHORT_TAG[<>]ifelse(LONG_TAG,,,; LONG_TAG)>]),
+ [<;>],[<,>])", ifelse(ARGNAME,,[<NULL, 0>],
+[<ifelse(ARGTYPE,[<optional_argument>],
+[<patsubst([<ARGNAME>],[<\[\(.*\)\]>],[<N_("\1"), 1>])>],[<N_("ARGNAME"), 0>])>]), N_("DOCSTRING") },
+divert(-1)>])
+popdef([<ARGTYPE>])
+popdef([<ARGNAME>])
+popdef([<DOCSTRING>])
divert(4)dnl
+popdef([<LONG_TAG>])dnl
+popdef([<SHORT_TAG>])dnl
SELECTOR
{
>])
@@ -135,39 +167,40 @@ define([<END>],[<
divert(-1)
undefine([<SELECTOR>])>])
-dnl GETOPT(argc, argv, [long_index])
+dnl GETOPT(argc, argv, [optindex])
dnl Emit option parsing code. Arguments:
dnl
dnl argc Name of the 1st argument to getopt_long.
dnl argv Name of the 2nd argument to getopt_long.
-dnl long_index Name of the 5th argument to getopt_long. If not given,
-dnl NULL will be passed
+dnl optindex Variable to assign optind to.
dnl
define([<GETOPT>],[<
{
int c;
- pushdef([<INDEX>],[<ifelse([<$#>],3,[<&$3>],[<NULL>])>])dnl
while ((c = getopt_long($1, $2, "SHORT_OPTS",
- long_options, INDEX)) != EOF)
+ long_options, NULL)) != EOF)
{
switch (c)
{
+ default:
+ exit(1);
undivert(4)
}
}
- popdef([<INDEX>])