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