4 * Copyright (c) 1997-2009 Erez Zadok
5 * Copyright (c) 2005 Daniel P. Ottavio
6 * Copyright (c) 1989 Jan-Simon Pendry
7 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
8 * Copyright (c) 1989 The Regents of the University of California.
11 * This code is derived from software contributed to Berkeley by
12 * Jan-Simon Pendry at Imperial College, London.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgment:
24 * This product includes software developed by the University of
25 * California, Berkeley and its contributors.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 * File: am-utils/amd/sun2amd.c
48 * Translate Sun-syntax maps to Amd maps
53 #endif /* HAVE_CONFIG_H */
59 /* dummies to make the program compile and link */
60 struct amu_global_options gopt
;
61 #if defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP)
62 # ifdef NEED_LIBWRAP_SEVERITY_VARIABLES
64 * Some systems that define libwrap already define these two variables
65 * in libwrap, while others don't: so I need to know precisely iff
66 * to define these two severity variables.
68 int allow_severity
=0, deny_severity
=0, rfc931_timeout
=0;
69 # endif /* NEED_LIBWRAP_SEVERITY_VARIABLES */
70 #endif /* defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */
74 * Parse the stream sun_in, convert the map information to amd, write
75 * the results to amd_out.
78 sun2amd_convert(FILE *sun_in
, FILE *amd_out
)
80 char line_buff
[INFO_MAX_LINE_LEN
], *tmp
, *key
, *entry
;
81 int pos
, line
= 0, retval
= 1;
84 memset(line_buff
, 0, sizeof(line_buff
));
86 /* Read the input line by line and do the conversion. */
87 while ((pos
= file_read_line(line_buff
, sizeof(line_buff
), sun_in
))) {
89 line_buff
[pos
- 1] = '\0';
92 if ((tmp
= strchr(line_buff
, '#')) != NULL
) {
96 /* find start of key */
98 while (*key
!= '\0' && isspace((unsigned char)*key
)) {
102 /* ignore blank lines */
107 /* find the end of the key and NULL terminate */
109 while (*tmp
!= '\0' && isspace((unsigned char)*tmp
) == 0) {
113 plog(XLOG_ERROR
, "map line %d has no entry", line
);
118 plog(XLOG_ERROR
, "map line %d has no entry", line
);
123 /* convert the sun entry to an amd entry */
124 if ((tmp
= sun_entry2amd(key
, entry
)) == NULL
) {
125 plog(XLOG_ERROR
, "parse error on line %d", line
);
129 if (fprintf(amd_out
, "%s %s\n", key
, tmp
) < 0) {
130 plog(XLOG_ERROR
, "can't write to output stream: %s", strerror(errno
));
134 /* just to be safe */
135 memset(line_buff
, 0, sizeof(line_buff
));
147 * wrapper open function
150 sun2amd_open(const char *path
, const char *mode
)
154 if ((retval
= fopen(path
,mode
)) == NULL
) {
155 plog(XLOG_ERROR
,"could not open file %s",path
);
163 * echo the usage and exit
169 "usage : sun2amd [-hH] [-i infile] [-o outfile]\n"
171 "-i\tspecify an infile (defaults to stdin)\n"
172 "-o\tspecify an outfile (defaults to stdout)\n");
177 main(int argc
, char **argv
)
179 /* default in/out to stdin/stdout */
180 FILE *sun_in
= stdin
, *amd_out
= stdout
;
183 while ((opt
= getopt(argc
, argv
, "i:o:hH")) != -1) {
187 if ((sun_in
= sun2amd_open(optarg
,"r")) == NULL
) {
193 if ((amd_out
= sun2amd_open(optarg
,"w")) == NULL
) {
205 retval
= sun2amd_convert(sun_in
,amd_out
);