1 #include <config.h> 2 3 /* things everything seems to need */ 4 #include <stdio.h> 5 #include <sys/param.h> 6 #include <sys/socket.h> 7 #include <sys/file.h> 8 #include <sys/stat.h> 9 #include <fcntl.h> 10 #include <netinet/in.h> 11 #include <sys/un.h> 12 #include <arpa/inet.h> 13 #include <netdb.h> 14 #include <ctype.h> 15 #include <signal.h> 16 17 /* If, when processing a logfile for replaying the last N lines, 18 * we end up seeing more than MAXREPLAYLINELEN characters in a line, 19 * abort processing and display the data. Why? There could be some 20 * very large logfiles and very long lines and we'd chew up lots of 21 * memory and send a LOT of data down to the client - all potentially 22 * bad. If there's a line over this in size, would you really want to 23 * see the whole thing (and possibly others)? 24 */ 25 #if !defined(MAXREPLAYLINELEN) 26 # define MAXREPLAYLINELEN 10000 27 #endif 28 29 /* the default escape sequence used to give meta commands 30 */ 31 #if !defined(DEFATTN) 32 # define DEFATTN '\005' 33 #endif 34 #if !defined(DEFESC) 35 # define DEFESC 'c' 36 #endif 37 38 /* set the default length of the replay functions 39 * DEFREPLAY for 'r' 40 * DEFPLAYBACK for 'p' 41 */ 42 #if !defined(DEFREPLAY) 43 # define DEFREPLAY 20 44 #endif 45 #if !defined(PLAYBACK) 46 # define DEFPLAYBACK 60 47 #endif 48 49 /* For legacy compile-time setting of the port... 50 */ 51 #if ! defined(DEFPORT) 52 # if defined(SERVICENAME) 53 # define DEFPORT SERVICENAME 54 # else 55 # if defined(PORTNUMBER) 56 # define DEFPORT PORTNUMBER 57 # else 58 # define DEFPORT "conserver" 59 # endif 60 # endif 61 #endif 62 63 #if STDC_HEADERS 64 # include <string.h> 65 # include <stdlib.h> 66 #else 67 # include <strings.h> 68 # ifndef HAVE_STRCHR 69 # define strchr index 70 # define strrchr rindex 71 # endif 72 #endif 73 #if !HAVE_STRCASECMP && HAVE_STRICMP 74 # define strcasecmp stricmp 75 # define strncasecmp strnicmp 76 #endif 77 78 #ifdef HAVE_UNISTD_H 79 # include <unistd.h> 80 #endif 81 82 /* if you do not have fd_set's here is a possible emulation 83 */ 84 #ifdef HAVE_SYS_SELECT_H 85 # include <sys/select.h> 86 #endif 87 88 #ifndef FD_ZERO 89 typedef long fd_set; 90 91 # define FD_ZERO(a) {*(a)=0;} 92 # define FD_SET(d,a) {*(a) |= (1 << (d));} 93 # define FD_CLR(d,a) {*(a) &= ~(1 << (d));} 94 # define FD_ISSET(d,a) (*(a) & (1 << (d))) 95 #endif 96 97 #ifdef HAVE_SYS_IOCTL_H 98 # include <sys/ioctl.h> 99 #endif 100 #ifdef HAVE_SYS_IOCTL_COMPAT_H 101 # include <sys/ioctl_compat.h> 102 #endif 103 104 #include <termios.h> 105 106 #ifndef TAB3 107 # ifdef OXTABS 108 # define TAB3 OXTABS 109 # else 110 # ifdef XTABS 111 # define TAB3 XTABS 112 # else 113 # define TAB3 0 114 # endif 115 # endif 116 #endif 117 118 #ifdef HAVE_STROPTS_H 119 # include <stropts.h> 120 #endif 121 122 123 #ifdef HAVE_TTYENT_H 124 # include <ttyent.h> 125 #endif 126 127 #ifdef HAVE_SYS_TTOLD_H 128 # include <sys/ttold.h> 129 #endif 130 131 #if HAVE_TYPES_H 132 # include <sys/types.h> 133 #endif 134 135 #if HAVE_SYS_WAIT_H 136 # include <sys/wait.h> 137 #endif 138 #define LO(s) ((unsigned)((s) & 0377)) 139 #define HI(s) ((unsigned)(((s) >> 8) & 0377)) 140 #if !defined(WIFEXITED) 141 # define WIFEXITED(s) (LO(s)==0) 142 #endif 143 #if !defined(WEXITSTATUS) 144 # define WEXITSTATUS(s) HI(s) 145 #endif 146 #if !defined(WIFSIGNALED) 147 # define WIFSIGNALED(s) ((LO(s)>0)&&(HI(s)==0)) 148 #endif 149 #if !defined(WTERMSIG) 150 # define WTERMSIG(s) (LO(s)&0177) 151 #endif 152 #if !defined(WIFSTOPPED) 153 # define WIFSTOPPED(s) ((LO(s)==0177)&&(HI(s)!=0)) 154 #endif 155 #if !defined(WSTOPSIG) 156 # define WSTOPSIG(s) HI(s) 157 #endif 158 159 #if HAVE_SYSEXITS_H 160 # include <sysexits.h> 161 #else 162 # define EX_OK 0 163 # define EX_UNAVAILABLE 69 164 # define EX_TEMPFAIL 75 165 #endif 166 167 #include <errno.h> 168 #if !defined(HAVE_STRERROR) 169 extern int errno; 170 extern char *sys_errlist[]; 171 # define strerror(Me) (sys_errlist[Me]) 172 #endif 173 174 #if HAVE_H_ERRLIST 175 extern int h_errno; 176 extern char *h_errlist[]; 177 # define hstrerror(Me) (h_errlist[Me]) 178 #else 179 # define hstrerror(Me) "host lookup error" 180 #endif 181 182 183 #if TIME_WITH_SYS_TIME 184 # include <sys/time.h> 185 # include <time.h> 186 #else 187 # if HAVE_SYS_TIME_H 188 # include <sys/time.h> 189 # else 190 # include <time.h> 191 # endif 192 #endif 193 194 195 #if HAVE_SHADOW_H 196 # include <shadow.h> 197 #endif 198 199 #ifdef HAVE_CRYPT_H 200 # include <crypt.h> 201 #endif 202 203 #ifdef HAVE_HPSECURITY_H 204 # include <hpsecurity.h> 205 #endif 206 207 #ifdef HAVE_PROT_H 208 # include <prot.h> 209 #endif 210 211 #ifdef HAVE_GETOPT_H 212 # include <getopt.h> 213 #endif 214 215 #ifdef HAVE_SYS_VLIMIT_H 216 # include <sys/vlimit.h> 217 #else 218 # include <limits.h> 219 #endif 220 221 #ifdef HAVE_SYS_RESOURCE_H 222 # include <sys/resource.h> 223 #endif 224 225 #ifdef HAVE_SYS_UIO_H 226 # include <sys/uio.h> 227 #endif 228 229 #ifdef HAVE_SYS_PROC_H 230 # include <sys/proc.h> 231 #endif 232 233 #ifdef HAVE_SYS_AUDIT_H 234 # include <sys/audit.h> 235 #endif 236 237 #ifdef HAVE_USERSEC_H 238 # include <usersec.h> 239 #endif 240 241 #ifdef HAVE_PTY_H 242 # include <pty.h> 243 #endif 244 245 #ifdef HAVE_LIBUTIL_H 246 # include <libutil.h> 247 #endif 248 249 #ifdef HAVE_UTIL_H 250 # include <util.h> 251 #endif 252 253 254 #ifndef NGROUPS_MAX 255 # define NGROUPS_MAX 8 256 #endif 257 258 #ifndef HAVE_GETSID 259 # define getsid(Mp) (Mp) 260 #endif 261 262 #ifndef HAVE_SETSID 263 # define setsid() getpid() 264 #endif 265 266 #ifndef HAVE_SETGROUPS 267 # define setgroups(x, y) 0 268 #endif 269 270 #ifndef HAVE_IN_ADDR_T 271 typedef unsigned long in_addr_t; 272 #endif 273 274 #ifndef HAVE_SOCKLEN_T 275 typedef int socklen_t; 276 #endif 277 278 /* 279 * IUCLC, OLCUC and XCASE were removed from IEEE Std 1003.1-200x 280 * as legacy definitions. 281 */ 282 #ifndef IUCLC 283 # define IUCLC 0 284 #endif 285 #ifndef OLCUC 286 # define OLCUC 0 287 #endif 288 #ifndef XCASE 289 # define XCASE 0 290 #endif 291 /* Some systems don't have OFILL or *DLY. */ 292 #ifndef OFILL 293 # define OFILL 0 294 #endif 295 #ifndef NLDLY 296 # define NLDLY 0 297 #endif 298 #ifndef CRDLY 299 # define CRDLY 0 300 #endif 301 #ifndef TABDLY 302 # define TABDLY 0 303 #endif 304 #ifndef BSDLY 305 # define BSDLY 0 306 #endif 307 #ifndef ONOCR 308 # define ONOCR 0 309 #endif 310 #ifndef ONLRET 311 # define ONLRET 0 312 #endif 313 314 #ifndef SEEK_SET 315 # define SEEK_SET L_SET 316 #endif 317 318 /* setup a conditional debugging line */ 319 #ifndef CONDDEBUG 320 # define CONDDEBUG(line) if (fDebug) {debugFileName=__FILE__; debugLineNo=__LINE__; Debug line;} 321 #endif 322 323 #if HAVE_DMALLOC 324 # include <dmalloc.h> 325 #endif 326 327 #if HAVE_FREEIPMI 328 # include <ipmiconsole.h> 329 #endif 330 331 #ifndef INADDR_STYPE 332 # if USE_IPV6 333 # define INADDR_STYPE struct sockaddr_storage 334 # else 335 # define INADDR_STYPE struct in_addr 336 # endif 337 #endif 338 339 #ifndef SOCKADDR_STYPE 340 # if USE_IPV6 341 # define SOCKADDR_STYPE struct sockaddr_storage 342 # else 343 # define SOCKADDR_STYPE struct sockaddr_in 344 # endif 345 #endif 346