Sat Aug 27 15:08:58 2011 UTC ()
Rename err() to avoid overlap with libc. Mark it dead.


(joerg)
diff -r1.25 -r1.26 src/libexec/fingerd/fingerd.c

cvs diff -r1.25 -r1.26 src/libexec/fingerd/fingerd.c (expand / switch to unified diff)

--- src/libexec/fingerd/fingerd.c 2009/03/14 13:59:28 1.25
+++ src/libexec/fingerd/fingerd.c 2011/08/27 15:08:58 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fingerd.c,v 1.25 2009/03/14 13:59:28 lukem Exp $ */ 1/* $NetBSD: fingerd.c,v 1.26 2011/08/27 15:08:58 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1993 4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -29,47 +29,46 @@ @@ -29,47 +29,46 @@
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__COPYRIGHT("@(#) Copyright (c) 1983, 1993\ 34__COPYRIGHT("@(#) Copyright (c) 1983, 1993\
35 The Regents of the University of California. All rights reserved."); 35 The Regents of the University of California. All rights reserved.");
36#endif /* not lint */ 36#endif /* not lint */
37 37
38#ifndef lint 38#ifndef lint
39#if 0 39#if 0
40static char sccsid[] = "from: @(#)fingerd.c 8.1 (Berkeley) 6/4/93"; 40static char sccsid[] = "from: @(#)fingerd.c 8.1 (Berkeley) 6/4/93";
41#else 41#else
42__RCSID("$NetBSD: fingerd.c,v 1.25 2009/03/14 13:59:28 lukem Exp $"); 42__RCSID("$NetBSD: fingerd.c,v 1.26 2011/08/27 15:08:58 joerg Exp $");
43#endif 43#endif
44#endif /* not lint */ 44#endif /* not lint */
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/socket.h> 47#include <sys/socket.h>
48#include <netinet/in.h> 48#include <netinet/in.h>
49#include <arpa/inet.h> 49#include <arpa/inet.h>
50#include <errno.h> 50#include <errno.h>
51 51
52#include <unistd.h> 52#include <unistd.h>
53#include <syslog.h> 53#include <syslog.h>
54#include <netdb.h> 54#include <netdb.h>
55#include <stdarg.h> 55#include <stdarg.h>
56#include <stdio.h> 56#include <stdio.h>
57#include <stdlib.h> 57#include <stdlib.h>
58#include <string.h> 58#include <string.h>
59#include "pathnames.h" 59#include "pathnames.h"
60 60
61void err(const char *, ...); 61__dead static void my_err(const char *, ...);
62int main(int, char *[]); 
63 62
64int 63int
65main(int argc, char *argv[]) 64main(int argc, char *argv[])
66{ 65{
67 FILE *fp; 66 FILE *fp;
68 int ch, ac = 2; 67 int ch, ac = 2;
69 char *lp = NULL /* XXX gcc */; 68 char *lp = NULL /* XXX gcc */;
70 struct sockaddr_storage ss; 69 struct sockaddr_storage ss;
71 int p[2], logging, no_forward, user_required, short_list; 70 int p[2], logging, no_forward, user_required, short_list;
72 socklen_t sval; 71 socklen_t sval;
73#define ENTRIES 50 72#define ENTRIES 50
74 char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog, *s; 73 char **ap, *av[ENTRIES + 1], **comp, line[1024], *prog, *s;
75#if 0 74#if 0
@@ -107,60 +106,60 @@ main(int argc, char *argv[]) @@ -107,60 +106,60 @@ main(int argc, char *argv[])
107 av[ac++] = __UNCONST("-m"); 106 av[ac++] = __UNCONST("-m");
108 break; 107 break;
109 case 'p': 108 case 'p':
110 av[ac++] = __UNCONST("-p"); 109 av[ac++] = __UNCONST("-p");
111 break; 110 break;
112 case 'g': 111 case 'g':
113 av[ac++] = __UNCONST("-g"); 112 av[ac++] = __UNCONST("-g");
114 break; 113 break;
115 case '8': 114 case '8':
116 av[ac++] = __UNCONST("-8"); 115 av[ac++] = __UNCONST("-8");
117 break; 116 break;
118 case '?': 117 case '?':
119 default: 118 default:
120 err("illegal option -- %c", optopt); 119 my_err("illegal option -- %c", optopt);
121 } 120 }
122 if (ac >= ENTRIES) 121 if (ac >= ENTRIES)
123 err("Too many options provided"); 122 my_err("Too many options provided");
124 } 123 }
125 124
126 125
127 if (logging) { 126 if (logging) {
128 sval = sizeof(ss); 127 sval = sizeof(ss);
129 if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0) 128 if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0)
130 err("getpeername: %s", strerror(errno)); 129 my_err("getpeername: %s", strerror(errno));
131 (void)getnameinfo((struct sockaddr *)&ss, sval, 130 (void)getnameinfo((struct sockaddr *)&ss, sval,
132 hostbuf, sizeof(hostbuf), NULL, 0, 0); 131 hostbuf, sizeof(hostbuf), NULL, 0, 0);
133 lp = hostbuf; 132 lp = hostbuf;
134 } 133 }
135  134
136 if (!fgets(line, sizeof(line), stdin)) { 135 if (!fgets(line, sizeof(line), stdin)) {
137 if (logging) 136 if (logging)
138 syslog(LOG_NOTICE, "query from %s", lp); 137 syslog(LOG_NOTICE, "query from %s", lp);
139 exit(1); 138 exit(1);
140 } 139 }
141 while ((s = strrchr(line, '\n')) != NULL || 140 while ((s = strrchr(line, '\n')) != NULL ||
142 (s = strrchr(line, '\r')) != NULL) 141 (s = strrchr(line, '\r')) != NULL)
143 *s = '\0'; 142 *s = '\0';
144 143
145 if (logging) { 144 if (logging) {
146 if (*line == '\0') 145 if (*line == '\0')
147 syslog(LOG_NOTICE, "query from %s", lp); 146 syslog(LOG_NOTICE, "query from %s", lp);
148 else 147 else
149 syslog(LOG_NOTICE, "query from %s: %s", lp, line); 148 syslog(LOG_NOTICE, "query from %s: %s", lp, line);
150 } 149 }
151 150
152 if (ac >= ENTRIES) 151 if (ac >= ENTRIES)
153 err("Too many options provided"); 152 my_err("Too many options provided");
154 av[ac++] = __UNCONST("--"); 153 av[ac++] = __UNCONST("--");
155 comp = &av[1]; 154 comp = &av[1];
156 for (lp = line, ap = &av[ac]; ac < ENTRIES;) { 155 for (lp = line, ap = &av[ac]; ac < ENTRIES;) {
157 if ((*ap = strtok(lp, " \t\r\n")) == NULL) 156 if ((*ap = strtok(lp, " \t\r\n")) == NULL)
158 break; 157 break;
159 lp = NULL; 158 lp = NULL;
160 if (no_forward && strchr(*ap, '@')) { 159 if (no_forward && strchr(*ap, '@')) {
161 (void) puts("forwarding service denied\r\n"); 160 (void) puts("forwarding service denied\r\n");
162 exit(1); 161 exit(1);
163 } 162 }
164 163
165 ch = strlen(*ap); 164 ch = strlen(*ap);
166 while ((*ap)[ch-1] == '@') 165 while ((*ap)[ch-1] == '@')
@@ -185,50 +184,50 @@ main(int argc, char *argv[]) @@ -185,50 +184,50 @@ main(int argc, char *argv[])
185 *comp = ++lp; 184 *comp = ++lp;
186 else 185 else
187 *comp = prog; 186 *comp = prog;
188 187
189 if (user_required) { 188 if (user_required) {
190 for (ap = comp + 1; strcmp("--", *(ap++)); ); 189 for (ap = comp + 1; strcmp("--", *(ap++)); );
191 if (*ap == NULL) { 190 if (*ap == NULL) {
192 (void) puts("must provide username\r\n"); 191 (void) puts("must provide username\r\n");
193 exit(1); 192 exit(1);
194 } 193 }
195 } 194 }
196 195
197 if (pipe(p) < 0) 196 if (pipe(p) < 0)
198 err("pipe: %s", strerror(errno)); 197 my_err("pipe: %s", strerror(errno));
199 198
200 switch(fork()) { 199 switch(fork()) {
201 case 0: 200 case 0:
202 (void) close(p[0]); 201 (void) close(p[0]);
203 if (p[1] != 1) { 202 if (p[1] != 1) {
204 (void) dup2(p[1], 1); 203 (void) dup2(p[1], 1);
205 (void) close(p[1]); 204 (void) close(p[1]);
206 } 205 }
207 execv(prog, comp); 206 execv(prog, comp);
208 err("execv: %s: %s", prog, strerror(errno)); 207 my_err("execv: %s: %s", prog, strerror(errno));
209 _exit(1); 208 _exit(1);
210 case -1: 209 case -1:
211 err("fork: %s", strerror(errno)); 210 my_err("fork: %s", strerror(errno));
212 } 211 }
213 (void) close(p[1]); 212 (void) close(p[1]);
214 if (!(fp = fdopen(p[0], "r"))) 213 if (!(fp = fdopen(p[0], "r")))
215 err("fdopen: %s", strerror(errno)); 214 my_err("fdopen: %s", strerror(errno));
216 while ((ch = getc(fp)) != EOF) { 215 while ((ch = getc(fp)) != EOF) {
217 if (ch == '\n') 216 if (ch == '\n')
218 putchar('\r'); 217 putchar('\r');
219 putchar(ch); 218 putchar(ch);
220 } 219 }
221 exit(0); 220 exit(0);
222} 221}
223 222
224void 223static void
225err(const char *fmt, ...) 224my_err(const char *fmt, ...)
226{ 225{
227 va_list ap; 226 va_list ap;
228 227
229 va_start(ap, fmt); 228 va_start(ap, fmt);
230 (void) vsyslog(LOG_ERR, fmt, ap); 229 (void) vsyslog(LOG_ERR, fmt, ap);
231 va_end(ap); 230 va_end(ap);
232 exit(1); 231 exit(1);
233 /* NOTREACHED */ 232 /* NOTREACHED */
234} 233}