2 * (c) Copyright 1992 by Panagiotis Tsirigotis
3 * (c) Sections Copyright 1998-2001 by Rob Braun
4 * All rights reserved. The file named COPYRIGHT specifies the terms
5 * and conditions for redistribution.
8 static char RCSid[] = "$Id: itox.c,v 1.3 2003/06/23 21:13:36 steveg Exp $" ;
11 #define EQ( s1, s2 ) ( strcmp( s1, s2 ) == 0 )
16 #define FIELD_WIDTH 15
17 #define DAEMON_DIR_OPTION "-daemon_dir"
18 #define TCPD_NAME "tcpd"
32 static void print_line( const char *name, const char *value );
33 static char *next_word( const char *description );
34 static char *make_string_cat( register unsigned count, ... );
35 static char *make_pathname( register unsigned count, ... );
39 * This program works only as a filter.
41 * -daemon_dir <dir_name> : if you use tcpd, this option specifies the
42 * directory where all the daemons are.
43 * You must specify this option if you use tcpd
45 * Note that we don't bother to free the memory we malloc.
47 int main(int argc, char *argv[] )
51 char *daemon_dirpath = "" ;
53 if ( argc != 1 && argc != 3 )
55 Sprint( 2, "Usage: %s [%s dir_path]\n",
56 basename( argv[ 0 ] ), DAEMON_DIR_OPTION ) ;
60 uses_tcpd = ( argc == 3 ) ;
66 daemon_dirpath = argv[ 2 ] ;
67 len = strlen( daemon_dirpath ) ;
68 if ( daemon_dirpath[ len-1 ] == '/' )
69 daemon_dirpath[ --len ] = NUL ;
72 strp = str_parse( (char *)0, " \t", STR_NOFLAGS, (int *)0 ) ;
74 while ( (s = Srdline( 0 )) )
78 char *socket_type, *protocol ;
84 if ( SIOLINELEN( 0 ) == 0 || s[ 0 ] == '#' )
87 str_setstr( strp, s ) ;
89 service = word = next_word( "service name" ) ;
92 * Check if it is an RPC service
94 p = strchr( word, '/' ) ;
97 Sprint( 1, "service %s\n{\n", word ) ;
98 if ( (is_rpc = ( p != NULL )) )
100 print_line( "type", "RPC" ) ;
101 print_line( "rpc_version", p+1 ) ;
104 socket_type = word = next_word( "socket type" ) ;
105 print_line( "socket_type", socket_type ) ;
107 word = next_word( "protocol" ) ;
108 p = strchr( word, '/' ) ;
109 protocol = ( p == NULL ) ? word : p+1 ;
111 print_line( "protocol", protocol ) ;
113 word = next_word( "wait/nowait" ) ;
114 p = strchr(word, '.');
118 "The entry for service %s/%s may be wrong, because\n",
121 "we can't convert .max option for wait/nowait field\n");
123 print_line( "wait", EQ( word, "wait" ) ? "yes" : "no" );
126 print_line( "wait", EQ( word, "wait" ) ? "yes" : "no" );
128 word = next_word( "user[.group]" ) ;
129 p = strchr(word, '.');
133 print_line( "user", word ) ;
135 print_line( "group", word );
138 print_line( "user", word ) ;
140 word = next_word( "server" ) ;
141 if ( EQ( word, "internal" ) )
144 * We are in trouble if this is an RPC service
149 "The entry for service %s will be wrong because\n", service ) ;
150 Sprint( 2, "we can't handle internal RPC services\n" ) ;
154 print_line( "type", "INTERNAL" ) ;
156 make_string_cat( 3, service,
157 "-", socket_type ) ) ;
162 char *server_path = word ; /* from inetd.conf */
163 char *server_of_server_path = basename( server_path ) ;
164 char *server_name = next_word( "server name" ) ;
165 char *server ; /* for xinetd config file */
167 if ( EQ( server_of_server_path, TCPD_NAME ) )
171 Sprint( 2, "You must use option %s if you use %s\n",
172 DAEMON_DIR_OPTION, TCPD_NAME ) ;
175 if ( server_name[ 0 ] == '/' )
176 server = server_name ;
178 server = make_pathname( 2,
179 daemon_dirpath, server_name ) ;
182 server = server_path ;
184 print_line( "server", server ) ;
186 word = str_component( strp ) ; /* 1st arg */
189 Sprint( 1, "\t%-*s = %s", FIELD_WIDTH,
190 "server_args", word ) ;
191 while ( (word = str_component( strp )) )
192 Sprint( 1, " %s", word ) ;
193 Sputchar( 1, '\n' ) ;
197 Sprint( 1, "}\n\n" ) ;
204 static void print_line( const char *name, const char *value )
206 Sprint( 1, "\t%-*s = %s\n", FIELD_WIDTH, name, value ) ;
210 static char *next_word( const char *description )
212 char *word = str_component( strp ) ;
216 Sprint( 2, "Line %d: %s missing \n", line_count, description ) ;
222 static char *make_string_cat( register unsigned count, ... )
225 register unsigned i ;
226 register unsigned len = 0 ;
227 register char *s, *p ;
233 va_start( ap, count ) ;
235 { /* 9 out of 10 have just 1, so this optimizes it */
236 s = va_arg( ap, char * ) ;
243 for ( i = 0 ; i < count ; i++ )
245 s = va_arg( ap, char * ) ;
252 newstring = (char *)malloc( len + 1 ) ;
253 if ( newstring == NULL )
257 va_start( ap, count ) ;
258 for ( i = 0 ; i < count ; i++ )
260 s = va_arg( ap, char * ) ;
263 while ( (*p++ = *s++) ) ;
267 newstring[len] = 0; /* if len == 0, must terminate or boom! */
271 static char *make_pathname( register unsigned count, ... )
274 register unsigned i ;
275 register unsigned len = 0 ;
276 register char *s, *p ;
282 va_start( ap, count ) ;
283 for ( i = 0 ; i < count ; i++ )
285 s = va_arg( ap, char * ) ;
290 pathname = (char *)malloc( len + count ) ;
291 if ( pathname == NULL )
295 va_start( ap, count ) ;
296 for ( i = 0 ; i < count ; i++ )
298 s = va_arg( ap, char * ) ;
299 while ( (*p++ = *s++) ) ;
300 *(p-1) = '/' ; /* change '\0' to '/' */