summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-06 16:50:45 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-03-06 16:50:45 (GMT)
commit248a97fbf0656d12839ca8986287d216820c9849 (patch) (side-by-side diff)
treee23c9635b7c752ca1b6ed95ecabc1590a18c548b
parent8f8a1c98f84669306d1489ddc5d55b6f589df9be (diff)
downloadalck-248a97fbf0656d12839ca8986287d216820c9849.tar.gz
alck-248a97fbf0656d12839ca8986287d216820c9849.tar.bz2
Remove site-specific defaults. Improve local-domain options.
* alck.1: Update. * alck.h (read_include): Remove. (freadlist, preadlist): New protos. * gram.y (usage): Update output. (main): Change -f to -T. Add -W option (read class w from a command stdout). Change handling of the -w option. Remove cwfile - there's no longer a default for -w. * lex.l (read_include): Rename to freadlist and rewrite. (preadlist): New function.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--alck.173
-rw-r--r--alck.h3
-rw-r--r--gram.y44
-rw-r--r--lex.l89
4 files changed, 164 insertions, 45 deletions
diff --git a/alck.1 b/alck.1
index 6e842ae..dfbb83f 100644
--- a/alck.1
+++ b/alck.1
@@ -15,3 +15,3 @@
.\" along with Alck. If not, see <http://www.gnu.org/licenses/>.
-.TH ALCK 1 "March 5, 2013" "ALCK"
+.TH ALCK 1 "March 6, 2013" "ALCK"
.SH NAME
@@ -31,2 +31,4 @@ alias files for consistency. The following tests are performed:
.TP
+.B Multiply defined aliases
+.TP
.B Transitivity test
@@ -35,2 +37,4 @@ This test discovers eventual circular dependencies.
.B Use of prohibited aliases
+This test is optional. When enabled, it detects the use of pipes,
+file redirects and includes in the input files.
.PP
@@ -81,2 +85,6 @@ treats them as parts of a single alias file.
.SH OPTIONS
+.SS General
+These options affect the behavior of the program in general. They can
+be specified anywhere in the command line and affect all options that
+follow them.
.TP
@@ -97,2 +105,51 @@ a dash (\fB\-\fR) reverts its sense.
.TP
+.B \-v
+Verbosely report the results.
+.SS Local domain names
+The distinction between local and remote email addreses allows
+.B alck
+to detect circular dependencies between aliases. A local email
+is any email that has no domain part, or whose domain part contains
+a
+.BR "local domain" .
+For
+.B Sendmail
+local domains are those that constitute the
+.B w
+class.
+.PP
+The following two options supply local domain names to
+.BR alck .
+They must appear in the command line before any filenames or
+.B \-T
+options.
+.TP
+\fB\-w\fR \fIFILE\fR
+Read local domain names from the given
+.IR FILE .
+The file should list each name on a separate line. Surrounding
+whitespace is allowed. Empty lines and
+comments (lines starting with the
+.B #
+character) are ignored.
+.TP
+\fB\-W\fR \fICOMMAND\fR
+Run \fICOMMAND\fR and read local domain names from its standard
+output.
+.B Alck
+will consider for inclusion only those lines that begin with
+alphanumeric character and don't contain whitespace. Thus, it is
+possible to read the local domain names from the
+.B Sendmail
+configuration with the following option:
+.sp
+.nf
+.in +2
+-W "echo '$=w' | sendmail -bt"
+.in
+.fi
+.SS Input options
+Input options can be interspersed with the input file names. They are
+processed in the order of their appearance.
+.TP
\fB\-T\fR \fIFILE\fR
@@ -114,15 +171,5 @@ This options cancels the effect of the previous
option.
-.TP
-.B \-v
-Verbosely report the results.
-.TP
-\fB\-w\fR \fIFILE\fR
-Read contents of the
-.BR Sendmail 's
-.B w
-class from the given
-.IR FILE .
-.PP
+.SS Informational
The following two options instruct the program to display a certain
-kind of information and exit:
+kind of information and exit.
.TP
diff --git a/alck.h b/alck.h
index 9af8db6..3d152f4 100644
--- a/alck.h
+++ b/alck.h
@@ -58,3 +58,4 @@ void slist_destroy(SLIST **plist);
-void read_include(SLIST **plist, char *name);
+void freadlist(SLIST **plist, char *name);
+void preadlist(SLIST **plist, char *progname);
diff --git a/gram.y b/gram.y
index 4da7cb2..271c50d 100644
--- a/gram.y
+++ b/gram.y
@@ -22,3 +22,4 @@ char *program_name;
SLIST *cw_list; /* List of domain names pertaining to Sendmail 'w' class */
-static int restricted; /* prohibit use of `special' aliases (pipes,
+
+static int restricted; /* prohibit the use of `special' aliases (pipes,
file redirections and includes */
@@ -102,3 +103,3 @@ email : string
$$ = NULL;
- read_include(&$$, $2);
+ freadlist(&$$, $2);
}
@@ -113,3 +114,3 @@ string: IDENT
int
-yyerror (char *s)
+yyerror(char *s)
{
@@ -176,3 +177,3 @@ usage()
printf(" a letter with '-' reverts its sense\n");
- printf(" -f FILE Read names of alias files from FILE\n");
+ printf(" -T FILE Read names of alias files from FILE\n");
printf(" -h Display this help list\n");
@@ -183,4 +184,6 @@ usage()
printf(" -V print program version and exit\n");
- printf(" -w FILE Read contents of Sendmail `w' class from the given\n");
- printf(" file.\n");
+ printf(" -w FILE Read local domain names from the FILE\n");
+ printf(" -W PROG Run PROG and read local domain names from"
+ " its stdout\n");
+
printf("\n");
@@ -212,3 +215,2 @@ main(int argc, char **argv)
int true = 1;
- char *cwfile = "/etc/mail/sendmail.cw";
SLIST *file_list; /* List of files to be read */
@@ -218,7 +220,5 @@ main(int argc, char **argv)
program_name = argv[0];
- while ((c = getopt(argc, argv, "-d:f:hp:ruVvw:")) != EOF) {
+ while ((c = getopt(argc, argv, "-d:hp:rT:uVvW:w:")) != EOF) {
switch (c) {
case 1:
- if (!cw_list)
- read_include(&cw_list, cwfile);
openaliases(optarg);
@@ -254,7 +254,5 @@ main(int argc, char **argv)
- case 'f':
- if (!cw_list)
- read_include(&cw_list, cwfile);
+ case 'T':
file_list = NULL;
- read_include(&file_list, optarg);
+ freadlist(&file_list, optarg);
if (file_list) {
@@ -287,3 +285,3 @@ main(int argc, char **argv)
version();
- exit (0);
+ exit(0);
@@ -291,4 +289,12 @@ main(int argc, char **argv)
if (file_count)
- error("-w must be used before first non-option argument");
- cwfile = optarg;
+ error("-w must be used before the first "
+ "non-option argument or -T option");
+ freadlist(&cw_list, optarg);
+ break;
+
+ case 'W':
+ if (file_count)
+ error("-W must be used before the first "
+ "non-option argument or -T option");
+ preadlist(&cw_list, optarg);
break;
@@ -296,3 +302,3 @@ main(int argc, char **argv)
default:
- exit (1);
+ exit(1);
}
@@ -303,4 +309,2 @@ main(int argc, char **argv)
- if (!cw_list)
- read_include(&cw_list, cwfile);
while (argc--) {
diff --git a/lex.l b/lex.l
index 85bd53f..e197957 100644
--- a/lex.l
+++ b/lex.l
@@ -198,3 +198,3 @@ lex_debug(int debug)
void
-read_include(SLIST **plist, char *name)
+freadlist(SLIST **plist, char *name)
{
@@ -202,4 +202,7 @@ read_include(SLIST **plist, char *name)
char buffer[256];
- FILE *fp = fopen(name, "r");
-
+ FILE *fp;
+ int line = 0;
+ int skipeol = 0;
+
+ fp = fopen(name, "r");
if (!fp) {
@@ -213,13 +216,29 @@ read_include(SLIST **plist, char *name)
while (p = fgets(buffer, sizeof buffer, fp)) {
- char *q;
-
+ size_t len = strlen(p);
+
+ line++;
+
+ if (len == 0)
+ continue;
+ if (p[len-1] != '\n') {
+ if (!feof(fp)) {
+ if (!skipeol)
+ parserror(name, line,
+ "line too long");
+ error_count++;
+ skipeol = 1;
+ }
+ } else if (skipeol)
+ continue;
+ else {
+ p[--len] = 0;
+ skipeol = 0;
+ }
+
while (*p && isspace(*p))
p++;
- if (*p == '#')
+ if (!*p || *p == '#')
continue;
- for (q = p + strlen(p) - 1; q > p && isspace(*q); q--)
- ;
- q[1] = 0;
- if (*p)
- slist_add(plist, p);
+
+ slist_add(plist, p);
}
@@ -227,2 +246,50 @@ read_include(SLIST **plist, char *name)
}
+
+void
+preadlist(SLIST **plist, char *progname)
+{
+ char *p;
+ char buffer[256];
+ FILE *fp;
+ int line = 0;
+ int skipeol = 0;
+
+ fp = popen(progname, "r");
+ if (!fp) {
+ parserror(file_name, line_num,
+ "cannot run `%s': %s",
+ progname, strerror(errno));
+ error_count++;
+ return;
+ }
+ while (p = fgets(buffer, sizeof buffer, fp)) {
+ size_t len = strlen(p);
+ char *q;
+
+ line++;
+
+ if (len == 0)
+ continue;
+ if (p[len-1] != '\n') {
+ if (!feof(fp)) {
+ if (!skipeol)
+ parserror(progname, line,
+ "line too long");
+ error_count++;
+ skipeol = 1;
+ }
+ } else if (skipeol)
+ continue;
+ else {
+ p[--len] = 0;
+ skipeol = 0;
+ }
+
+ if (!*p || !isalnum(*p) || p[strcspn(p, " \t")])
+ continue;
+
+ slist_add(plist, p);
+ }
+ pclose(fp);
+}

Return to:

Send suggestions and report system problems to the System administrator.