fingerd.c (181269) | fingerd.c (206038) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)fingerd.c 8.1 (Berkeley) 6/4/93"; 43#endif 44static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)fingerd.c 8.1 (Berkeley) 6/4/93"; 43#endif 44static const char rcsid[] = |
45 "$FreeBSD: head/libexec/fingerd/fingerd.c 181269 2008-08-04 01:25:48Z cperciva $"; | 45 "$FreeBSD: head/libexec/fingerd/fingerd.c 206038 2010-04-01 13:11:39Z des $"; |
46#endif /* not lint */ 47 48#include <sys/types.h> 49#include <sys/param.h> 50#include <sys/socket.h> 51#include <netinet/in.h> 52#include <netinet/tcp.h> 53#include <arpa/inet.h> --- 13 unchanged lines hidden (view full) --- 67int 68main(int argc, char *argv[]) 69{ 70 FILE *fp; 71 int ch; 72 char *lp; 73 struct sockaddr_storage ss; 74 socklen_t sval; | 46#endif /* not lint */ 47 48#include <sys/types.h> 49#include <sys/param.h> 50#include <sys/socket.h> 51#include <netinet/in.h> 52#include <netinet/tcp.h> 53#include <arpa/inet.h> --- 13 unchanged lines hidden (view full) --- 67int 68main(int argc, char *argv[]) 69{ 70 FILE *fp; 71 int ch; 72 char *lp; 73 struct sockaddr_storage ss; 74 socklen_t sval; |
75 int p[2], logging, pflag, secure; | 75 int p[2], debug, kflag, logging, pflag, secure; |
76#define ENTRIES 50 77 char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog; 78 char rhost[MAXHOSTNAMELEN]; 79 80 prog = _PATH_FINGER; | 76#define ENTRIES 50 77 char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog; 78 char rhost[MAXHOSTNAMELEN]; 79 80 prog = _PATH_FINGER; |
81 logging = pflag = secure = 0; | 81 logging = kflag = pflag = secure = 0; |
82 openlog("fingerd", LOG_PID | LOG_CONS, LOG_DAEMON); 83 opterr = 0; | 82 openlog("fingerd", LOG_PID | LOG_CONS, LOG_DAEMON); 83 opterr = 0; |
84 while ((ch = getopt(argc, argv, "lp:s")) != -1) | 84 while ((ch = getopt(argc, argv, "dklp:s")) != -1) |
85 switch (ch) { | 85 switch (ch) { |
86 case 'd': 87 debug = 1; 88 break; 89 case 'k': 90 kflag = 1; 91 break; |
|
86 case 'l': 87 logging = 1; 88 break; 89 case 'p': 90 prog = optarg; 91 pflag = 1; 92 break; 93 case 's': 94 secure = 1; 95 break; 96 case '?': 97 default: 98 logerr("illegal option -- %c", optopt); 99 } 100 101 /* 102 * Enable server-side Transaction TCP. 103 */ | 92 case 'l': 93 logging = 1; 94 break; 95 case 'p': 96 prog = optarg; 97 pflag = 1; 98 break; 99 case 's': 100 secure = 1; 101 break; 102 case '?': 103 default: 104 logerr("illegal option -- %c", optopt); 105 } 106 107 /* 108 * Enable server-side Transaction TCP. 109 */ |
104 { | 110 if (!debug) { |
105 int one = 1; 106 if (setsockopt(STDOUT_FILENO, IPPROTO_TCP, TCP_NOPUSH, &one, 107 sizeof one) < 0) { 108 logerr("setsockopt(TCP_NOPUSH) failed: %m"); 109 } 110 } 111 112 if (!fgets(line, sizeof(line), stdin)) 113 exit(1); 114 | 111 int one = 1; 112 if (setsockopt(STDOUT_FILENO, IPPROTO_TCP, TCP_NOPUSH, &one, 113 sizeof one) < 0) { 114 logerr("setsockopt(TCP_NOPUSH) failed: %m"); 115 } 116 } 117 118 if (!fgets(line, sizeof(line), stdin)) 119 exit(1); 120 |
115 if (logging || pflag) { | 121 if (!debug && (logging || pflag)) { |
116 sval = sizeof(ss); 117 if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0) 118 logerr("getpeername: %s", strerror(errno)); 119 realhostname_sa(rhost, sizeof rhost - 1, 120 (struct sockaddr *)&ss, sval); 121 rhost[sizeof(rhost) - 1] = '\0'; 122 if (pflag) 123 setenv("FINGERD_REMOTE_HOST", rhost, 1); --- 14 unchanged lines hidden (view full) --- 138 logerr("strdup: %s", strerror(errno)); 139 } 140 for (end = t; *end; end++) 141 if (*end == '\n' || *end == '\r') 142 *end = ' '; 143 syslog(LOG_NOTICE, "query from %s: `%s'", rhost, t); 144 } 145 | 122 sval = sizeof(ss); 123 if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0) 124 logerr("getpeername: %s", strerror(errno)); 125 realhostname_sa(rhost, sizeof rhost - 1, 126 (struct sockaddr *)&ss, sval); 127 rhost[sizeof(rhost) - 1] = '\0'; 128 if (pflag) 129 setenv("FINGERD_REMOTE_HOST", rhost, 1); --- 14 unchanged lines hidden (view full) --- 144 logerr("strdup: %s", strerror(errno)); 145 } 146 for (end = t; *end; end++) 147 if (*end == '\n' || *end == '\r') 148 *end = ' '; 149 syslog(LOG_NOTICE, "query from %s: `%s'", rhost, t); 150 } 151 |
146 comp = &av[1]; 147 av[2] = "--"; 148 for (lp = line, ap = &av[3];;) { | 152 comp = &av[2]; 153 av[3] = "--"; 154 if (kflag) 155 *comp-- = "-k"; 156 for (lp = line, ap = &av[4];;) { |
149 *ap = strtok(lp, " \t\r\n"); 150 if (!*ap) { | 157 *ap = strtok(lp, " \t\r\n"); 158 if (!*ap) { |
151 if (secure && ap == &av[3]) { | 159 if (secure && ap == &av[4]) { |
152 puts("must provide username\r\n"); 153 exit(1); 154 } 155 break; 156 } 157 if (secure && strchr(*ap, '@')) { 158 puts("forwarding service denied\r\n"); 159 exit(1); 160 } 161 162 /* RFC742: "/[Ww]" == "-l" */ 163 if ((*ap)[0] == '/' && ((*ap)[1] == 'W' || (*ap)[1] == 'w')) { | 160 puts("must provide username\r\n"); 161 exit(1); 162 } 163 break; 164 } 165 if (secure && strchr(*ap, '@')) { 166 puts("forwarding service denied\r\n"); 167 exit(1); 168 } 169 170 /* RFC742: "/[Ww]" == "-l" */ 171 if ((*ap)[0] == '/' && ((*ap)[1] == 'W' || (*ap)[1] == 'w')) { |
164 av[1] = "-l"; 165 comp = &av[0]; | 172 *comp-- = "-l"; |
166 } 167 else if (++ap == av + ENTRIES) { 168 *ap = NULL; 169 break; 170 } 171 lp = NULL; 172 } 173 174 if ((lp = strrchr(prog, '/')) != NULL) 175 *comp = ++lp; 176 else 177 *comp = prog; 178 if (pipe(p) < 0) 179 logerr("pipe: %s", strerror(errno)); 180 | 173 } 174 else if (++ap == av + ENTRIES) { 175 *ap = NULL; 176 break; 177 } 178 lp = NULL; 179 } 180 181 if ((lp = strrchr(prog, '/')) != NULL) 182 *comp = ++lp; 183 else 184 *comp = prog; 185 if (pipe(p) < 0) 186 logerr("pipe: %s", strerror(errno)); 187 |
188 if (debug) { 189 fprintf(stderr, "%s", prog); 190 for (ap = comp; *ap != NULL; ++ap) 191 fprintf(stderr, " %s", *ap); 192 fprintf(stderr, "\n"); 193 } 194 |
|
181 switch(vfork()) { 182 case 0: 183 (void)close(p[0]); 184 if (p[1] != STDOUT_FILENO) { 185 (void)dup2(p[1], STDOUT_FILENO); 186 (void)close(p[1]); 187 } 188 dup2(STDOUT_FILENO, STDERR_FILENO); --- 33 unchanged lines hidden --- | 195 switch(vfork()) { 196 case 0: 197 (void)close(p[0]); 198 if (p[1] != STDOUT_FILENO) { 199 (void)dup2(p[1], STDOUT_FILENO); 200 (void)close(p[1]); 201 } 202 dup2(STDOUT_FILENO, STDERR_FILENO); --- 33 unchanged lines hidden --- |