1 /*
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.
6 */
7
8 #include "config.h"
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <syslog.h>
12 #include <signal.h>
13 #include <unistd.h>
14
15 #include "special.h"
16 #include "server.h"
17 #include "msg.h"
18 #include "sconst.h"
19 #include "int.h"
20 #include "util.h"
21 #include "nvlists.h"
22 #include "service.h"
23 #include "state.h"
24 #include "main.h"
25 #include "connection.h"
26 #include "sconf.h"
27 #include "options.h"
28 #include "xconfig.h"
29 #include "ident.h"
30
31
32 static void stream_logging( struct server *) ;
33
34 static const struct builtin_service special_services[] =
35 {
36 { LOG_SERVICE_NAME, SOCK_STREAM, { stream_logging, FORK } },
37 { INTERCEPT_SERVICE_NAME, SOCK_STREAM, { intercept, FORK } },
38 { INTERCEPT_SERVICE_NAME, SOCK_DGRAM, { intercept, FORK } },
39 { NULL, 0, { NULL, 0 } }
40 } ;
41
42
spec_find(const char * service_name,int type)43 const builtin_s *spec_find( const char *service_name, int type )
44 {
45 const builtin_s *bp ;
46 const struct name_value *nvp ;
47 const char *func = "spec_find" ;
48
49 if ( (bp = builtin_lookup( special_services, service_name, type )) )
50 return( bp ) ;
51
52 nvp = nv_find_name( socket_types, type ) ;
53 if ( nvp == NULL )
54 {
55 msg( LOG_ERR, func, "unknown socket type: %d", type ) ;
56 return( NULL ) ;
57 }
58
59 msg( LOG_ERR, func,
60 "special service %s,%s not supported", service_name, nvp->name ) ;
61 return( NULL ) ;
62 }
63
64
spec_service_handler(struct service * sp,connection_s * cp)65 status_e spec_service_handler( struct service *sp, connection_s *cp )
66 {
67 return(server_run( sp, cp ));
68 }
69
70
spec_setup(const char * name,int socket_type,int instances)71 static struct service *spec_setup( const char *name, int socket_type,
72 int instances )
73 {
74 const builtin_s *bp ;
75 struct service_config *scp ;
76
77 bp = spec_find( name, socket_type ) ;
78 if ( bp == NULL )
79 return( NULL ) ;
80
81 if ( ( scp = sc_make_special( name, bp, instances ) ) == NULL )
82 return( NULL ) ;
83
84 return( svc_make_special( scp ) ) ;
85 }
86
87
88 /*
89 * Initialize the special services and the corresponding entries in
90 * the program state structure.
91 */
spec_include(void)92 void spec_include(void)
93 {
94 int instances ;
95
96 instances = logprocs_option ? logprocs_option_arg : DEFAULT_LOGPROCS ;
97 LOG_SERVICE( ps ) = spec_setup( LOG_SERVICE_NAME, SOCK_STREAM, instances ) ;
98 }
99
100
stream_logging(struct server * serp)101 static void stream_logging( struct server *serp )
102 {
103 const char *func = "stream_logging" ;
104 idresult_e result ;
105
106 #ifdef DEBUG_LOGGING
107 if ( debug.on )
108 {
109 msg( LOG_DEBUG, func, "%d is sleeping", getpid() ) ;
110 sleep( 10 ) ;
111 }
112 #endif
113
114 result = log_remote_user( serp, LOGUSER_FAILURE_TIMEOUT ) ;
115 if ( (result != IDR_OK) && (result != IDR_NOSERVER) )
116 msg( LOG_ERR, func, "Failed to contact identity server at %s: %s", conn_addrstr( SERVER_CONNECTION( serp ) ), idresult_explain( result ) ) ;
117 }
118
119