aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-06 18:50:45 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-03-06 18:50:45 +0200
commit248a97fbf0656d12839ca8986287d216820c9849 (patch)
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.
-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 @@
15.\" along with Alck. If not, see <http://www.gnu.org/licenses/>. 15.\" along with Alck. If not, see <http://www.gnu.org/licenses/>.
16.TH ALCK 1 "March 5, 2013" "ALCK" 16.TH ALCK 1 "March 6, 2013" "ALCK"
17.SH NAME 17.SH NAME
@@ -31,2 +31,4 @@ alias files for consistency. The following tests are performed:
31.TP 31.TP
32.B Multiply defined aliases
33.TP
32.B Transitivity test 34.B Transitivity test
@@ -35,2 +37,4 @@ This test discovers eventual circular dependencies.
35.B Use of prohibited aliases 37.B Use of prohibited aliases
38This test is optional. When enabled, it detects the use of pipes,
39file redirects and includes in the input files.
36.PP 40.PP
@@ -81,2 +85,6 @@ treats them as parts of a single alias file.
81.SH OPTIONS 85.SH OPTIONS
86.SS General
87These options affect the behavior of the program in general. They can
88be specified anywhere in the command line and affect all options that
89follow them.
82.TP 90.TP
@@ -97,2 +105,51 @@ a dash (\fB\-\fR) reverts its sense.
97.TP 105.TP
106.B \-v
107Verbosely report the results.
108.SS Local domain names
109The distinction between local and remote email addreses allows
110.B alck
111to detect circular dependencies between aliases. A local email
112is any email that has no domain part, or whose domain part contains
113a
114.BR "local domain" .
115For
116.B Sendmail
117local domains are those that constitute the
118.B w
119class.
120.PP
121The following two options supply local domain names to
122.BR alck .
123They must appear in the command line before any filenames or
124.B \-T
125options.
126.TP
127\fB\-w\fR \fIFILE\fR
128Read local domain names from the given
129.IR FILE .
130The file should list each name on a separate line. Surrounding
131whitespace is allowed. Empty lines and
132comments (lines starting with the
133.B #
134character) are ignored.
135.TP
136\fB\-W\fR \fICOMMAND\fR
137Run \fICOMMAND\fR and read local domain names from its standard
138output.
139.B Alck
140will consider for inclusion only those lines that begin with
141alphanumeric character and don't contain whitespace. Thus, it is
142possible to read the local domain names from the
143.B Sendmail
144configuration with the following option:
145.sp
146.nf
147.in +2
148-W "echo '$=w' | sendmail -bt"
149.in
150.fi
151.SS Input options
152Input options can be interspersed with the input file names. They are
153processed in the order of their appearance.
154.TP
98\fB\-T\fR \fIFILE\fR 155\fB\-T\fR \fIFILE\fR
@@ -114,15 +171,5 @@ This options cancels the effect of the previous
114option. 171option.
115.TP 172.SS Informational
116.B \-v
117Verbosely report the results.
118.TP
119\fB\-w\fR \fIFILE\fR
120Read contents of the
121.BR Sendmail 's
122.B w
123class from the given
124.IR FILE .
125.PP
126The following two options instruct the program to display a certain 173The following two options instruct the program to display a certain
127kind of information and exit: 174kind of information and exit.
128.TP 175.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);
58 58
59void read_include(SLIST **plist, char *name); 59void freadlist(SLIST **plist, char *name);
60void preadlist(SLIST **plist, char *progname);
60 61
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;
22SLIST *cw_list; /* List of domain names pertaining to Sendmail 'w' class */ 22SLIST *cw_list; /* List of domain names pertaining to Sendmail 'w' class */
23static int restricted; /* prohibit use of `special' aliases (pipes, 23
24static int restricted; /* prohibit the use of `special' aliases (pipes,
24 file redirections and includes */ 25 file redirections and includes */
@@ -102,3 +103,3 @@ email : string
102 $$ = NULL; 103 $$ = NULL;
103 read_include(&$$, $2); 104 freadlist(&$$, $2);
104 } 105 }
@@ -113,3 +114,3 @@ string: IDENT
113int 114int
114yyerror (char *s) 115yyerror(char *s)
115{ 116{
@@ -176,3 +177,3 @@ usage()
176 printf(" a letter with '-' reverts its sense\n"); 177 printf(" a letter with '-' reverts its sense\n");
177 printf(" -f FILE Read names of alias files from FILE\n"); 178 printf(" -T FILE Read names of alias files from FILE\n");
178 printf(" -h Display this help list\n"); 179 printf(" -h Display this help list\n");
@@ -183,4 +184,6 @@ usage()
183 printf(" -V print program version and exit\n"); 184 printf(" -V print program version and exit\n");
184 printf(" -w FILE Read contents of Sendmail `w' class from the given\n"); 185 printf(" -w FILE Read local domain names from the FILE\n");
185 printf(" file.\n"); 186 printf(" -W PROG Run PROG and read local domain names from"
187 " its stdout\n");
188
186 printf("\n"); 189 printf("\n");
@@ -212,3 +215,2 @@ main(int argc, char **argv)
212 int true = 1; 215 int true = 1;
213 char *cwfile = "/etc/mail/sendmail.cw";
214 SLIST *file_list; /* List of files to be read */ 216 SLIST *file_list; /* List of files to be read */
@@ -218,7 +220,5 @@ main(int argc, char **argv)
218 program_name = argv[0]; 220 program_name = argv[0];
219 while ((c = getopt(argc, argv, "-d:f:hp:ruVvw:")) != EOF) { 221 while ((c = getopt(argc, argv, "-d:hp:rT:uVvW:w:")) != EOF) {
220 switch (c) { 222 switch (c) {
221 case 1: 223 case 1:
222 if (!cw_list)
223 read_include(&cw_list, cwfile);
224 openaliases(optarg); 224 openaliases(optarg);
@@ -254,7 +254,5 @@ main(int argc, char **argv)
254 254
255 case 'f': 255 case 'T':
256 if (!cw_list)
257 read_include(&cw_list, cwfile);
258 file_list = NULL; 256 file_list = NULL;
259 read_include(&file_list, optarg); 257 freadlist(&file_list, optarg);
260 if (file_list) { 258 if (file_list) {
@@ -287,3 +285,3 @@ main(int argc, char **argv)
287 version(); 285 version();
288 exit (0); 286 exit(0);
289 287
@@ -291,4 +289,12 @@ main(int argc, char **argv)
291 if (file_count) 289 if (file_count)
292 error("-w must be used before first non-option argument"); 290 error("-w must be used before the first "
293 cwfile = optarg; 291 "non-option argument or -T option");
292 freadlist(&cw_list, optarg);
293 break;
294
295 case 'W':
296 if (file_count)
297 error("-W must be used before the first "
298 "non-option argument or -T option");
299 preadlist(&cw_list, optarg);
294 break; 300 break;
@@ -296,3 +302,3 @@ main(int argc, char **argv)
296 default: 302 default:
297 exit (1); 303 exit(1);
298 } 304 }
@@ -303,4 +309,2 @@ main(int argc, char **argv)
303 309
304 if (!cw_list)
305 read_include(&cw_list, cwfile);
306 while (argc--) { 310 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)
198void 198void
199read_include(SLIST **plist, char *name) 199freadlist(SLIST **plist, char *name)
200{ 200{
@@ -202,4 +202,7 @@ read_include(SLIST **plist, char *name)
202 char buffer[256]; 202 char buffer[256];
203 FILE *fp = fopen(name, "r"); 203 FILE *fp;
204 204 int line = 0;
205 int skipeol = 0;
206
207 fp = fopen(name, "r");
205 if (!fp) { 208 if (!fp) {
@@ -213,13 +216,29 @@ read_include(SLIST **plist, char *name)
213 while (p = fgets(buffer, sizeof buffer, fp)) { 216 while (p = fgets(buffer, sizeof buffer, fp)) {
214 char *q; 217 size_t len = strlen(p);
215 218
219 line++;
220
221 if (len == 0)
222 continue;
223 if (p[len-1] != '\n') {
224 if (!feof(fp)) {
225 if (!skipeol)
226 parserror(name, line,
227 "line too long");
228 error_count++;
229 skipeol = 1;
230 }
231 } else if (skipeol)
232 continue;
233 else {
234 p[--len] = 0;
235 skipeol = 0;
236 }
237
216 while (*p && isspace(*p)) 238 while (*p && isspace(*p))
217 p++; 239 p++;
218 if (*p == '#') 240 if (!*p || *p == '#')
219 continue; 241 continue;
220 for (q = p + strlen(p) - 1; q > p && isspace(*q); q--) 242
221 ; 243 slist_add(plist, p);
222 q[1] = 0;
223 if (*p)
224 slist_add(plist, p);
225 } 244