Deleted Added
full compact
syslogd.c (144984) syslogd.c (146187)
1/*
2 * Copyright (c) 1983, 1988, 1993, 1994
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

--- 26 unchanged lines hidden (view full) ---

35
36#ifndef lint
37#if 0
38static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
39#endif
40#endif /* not lint */
41
42#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1983, 1988, 1993, 1994
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

--- 26 unchanged lines hidden (view full) ---

35
36#ifndef lint
37#if 0
38static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
39#endif
40#endif /* not lint */
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/usr.sbin/syslogd/syslogd.c 144984 2005-04-13 03:19:41Z hrs $");
43__FBSDID("$FreeBSD: head/usr.sbin/syslogd/syslogd.c 146187 2005-05-13 16:31:11Z ume $");
44
45/*
46 * syslogd -- log system messages
47 *
48 * This program implements a system log. It takes a series of lines.
49 * Each line may have a priority, signified as "<n>" as
50 * the first characters of the line. If this is
51 * not present, a default priority is used.

--- 56 unchanged lines hidden (view full) ---

108#include <utmp.h>
109
110#include "pathnames.h"
111#include "ttymsg.h"
112
113#define SYSLOG_NAMES
114#include <sys/syslog.h>
115
44
45/*
46 * syslogd -- log system messages
47 *
48 * This program implements a system log. It takes a series of lines.
49 * Each line may have a priority, signified as "<n>" as
50 * the first characters of the line. If this is
51 * not present, a default priority is used.

--- 56 unchanged lines hidden (view full) ---

108#include <utmp.h>
109
110#include "pathnames.h"
111#include "ttymsg.h"
112
113#define SYSLOG_NAMES
114#include <sys/syslog.h>
115
116#ifdef NI_WITHSCOPEID
117static const int withscopeid = NI_WITHSCOPEID;
118#else
119static const int withscopeid;
120#endif
121
122const char *ConfFile = _PATH_LOGCONF;
123const char *PidFile = _PATH_LOGPID;
124const char ctty[] = _PATH_CONSOLE;
125
126#define dprintf if (Debug) printf
127
128#define MAXUNAMES 20 /* maximum number of user names */
129

--- 1251 unchanged lines hidden (view full) ---

1381cvthname(struct sockaddr *f)
1382{
1383 int error, hl;
1384 sigset_t omask, nmask;
1385 static char hname[NI_MAXHOST], ip[NI_MAXHOST];
1386
1387 error = getnameinfo((struct sockaddr *)f,
1388 ((struct sockaddr *)f)->sa_len,
116const char *ConfFile = _PATH_LOGCONF;
117const char *PidFile = _PATH_LOGPID;
118const char ctty[] = _PATH_CONSOLE;
119
120#define dprintf if (Debug) printf
121
122#define MAXUNAMES 20 /* maximum number of user names */
123

--- 1251 unchanged lines hidden (view full) ---

1375cvthname(struct sockaddr *f)
1376{
1377 int error, hl;
1378 sigset_t omask, nmask;
1379 static char hname[NI_MAXHOST], ip[NI_MAXHOST];
1380
1381 error = getnameinfo((struct sockaddr *)f,
1382 ((struct sockaddr *)f)->sa_len,
1389 ip, sizeof ip, NULL, 0,
1390 NI_NUMERICHOST | withscopeid);
1383 ip, sizeof ip, NULL, 0, NI_NUMERICHOST);
1391 dprintf("cvthname(%s)\n", ip);
1392
1393 if (error) {
1394 dprintf("Malformed from address %s\n", gai_strerror(error));
1395 return ("???");
1396 }
1397 if (!resolve)
1398 return (ip);
1399
1400 sigemptyset(&nmask);
1401 sigaddset(&nmask, SIGHUP);
1402 sigprocmask(SIG_BLOCK, &nmask, &omask);
1403 error = getnameinfo((struct sockaddr *)f,
1404 ((struct sockaddr *)f)->sa_len,
1384 dprintf("cvthname(%s)\n", ip);
1385
1386 if (error) {
1387 dprintf("Malformed from address %s\n", gai_strerror(error));
1388 return ("???");
1389 }
1390 if (!resolve)
1391 return (ip);
1392
1393 sigemptyset(&nmask);
1394 sigaddset(&nmask, SIGHUP);
1395 sigprocmask(SIG_BLOCK, &nmask, &omask);
1396 error = getnameinfo((struct sockaddr *)f,
1397 ((struct sockaddr *)f)->sa_len,
1405 hname, sizeof hname, NULL, 0,
1406 NI_NAMEREQD | withscopeid);
1398 hname, sizeof hname, NULL, 0, NI_NAMEREQD);
1407 sigprocmask(SIG_SETMASK, &omask, NULL);
1408 if (error) {
1409 dprintf("Host name for your address (%s) unknown\n", ip);
1410 return (ip);
1411 }
1412 hl = strlen(hname);
1413 if (hl > 0 && hname[hl-1] == '.')
1414 hname[--hl] = '\0';

--- 816 unchanged lines hidden (view full) ---

2231 }
2232
2233 if (Debug) {
2234 printf("allowaddr: rule %d: ", NumAllowed);
2235 if (ap.isnumeric) {
2236 printf("numeric, ");
2237 getnameinfo((struct sockaddr *)&ap.a_addr,
2238 ((struct sockaddr *)&ap.a_addr)->sa_len,
1399 sigprocmask(SIG_SETMASK, &omask, NULL);
1400 if (error) {
1401 dprintf("Host name for your address (%s) unknown\n", ip);
1402 return (ip);
1403 }
1404 hl = strlen(hname);
1405 if (hl > 0 && hname[hl-1] == '.')
1406 hname[--hl] = '\0';

--- 816 unchanged lines hidden (view full) ---

2223 }
2224
2225 if (Debug) {
2226 printf("allowaddr: rule %d: ", NumAllowed);
2227 if (ap.isnumeric) {
2228 printf("numeric, ");
2229 getnameinfo((struct sockaddr *)&ap.a_addr,
2230 ((struct sockaddr *)&ap.a_addr)->sa_len,
2239 ip, sizeof ip, NULL, 0,
2240 NI_NUMERICHOST | withscopeid);
2231 ip, sizeof ip, NULL, 0, NI_NUMERICHOST);
2241 printf("addr = %s, ", ip);
2242 getnameinfo((struct sockaddr *)&ap.a_mask,
2243 ((struct sockaddr *)&ap.a_mask)->sa_len,
2232 printf("addr = %s, ", ip);
2233 getnameinfo((struct sockaddr *)&ap.a_mask,
2234 ((struct sockaddr *)&ap.a_mask)->sa_len,
2244 ip, sizeof ip, NULL, 0,
2245 NI_NUMERICHOST | withscopeid);
2235 ip, sizeof ip, NULL, 0, NI_NUMERICHOST);
2246 printf("mask = %s; ", ip);
2247 } else {
2248 printf("domainname = %s; ", ap.a_name);
2249 }
2250 printf("port = %d\n", ap.port);
2251 }
2252
2253 if ((AllowedPeers = realloc(AllowedPeers,

--- 32 unchanged lines hidden (view full) ---

2286 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
2287 if (getaddrinfo(name, NULL, &hints, &res) == 0)
2288 freeaddrinfo(res);
2289 else if (strchr(name, '.') == NULL) {
2290 strlcat(name, ".", sizeof name);
2291 strlcat(name, LocalDomain, sizeof name);
2292 }
2293 if (getnameinfo(sa, sa->sa_len, ip, sizeof ip, port, sizeof port,
2236 printf("mask = %s; ", ip);
2237 } else {
2238 printf("domainname = %s; ", ap.a_name);
2239 }
2240 printf("port = %d\n", ap.port);
2241 }
2242
2243 if ((AllowedPeers = realloc(AllowedPeers,

--- 32 unchanged lines hidden (view full) ---

2276 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
2277 if (getaddrinfo(name, NULL, &hints, &res) == 0)
2278 freeaddrinfo(res);
2279 else if (strchr(name, '.') == NULL) {
2280 strlcat(name, ".", sizeof name);
2281 strlcat(name, LocalDomain, sizeof name);
2282 }
2283 if (getnameinfo(sa, sa->sa_len, ip, sizeof ip, port, sizeof port,
2294 NI_NUMERICHOST | withscopeid | NI_NUMERICSERV) != 0)
2284 NI_NUMERICHOST | NI_NUMERICSERV) != 0)
2295 return (0); /* for safety, should not occur */
2296 dprintf("validate: dgram from IP %s, port %s, name %s;\n",
2297 ip, port, name);
2298 sport = atoi(port);
2299
2300 /* now, walk down the list */
2301 for (i = 0, ap = AllowedPeers; i < NumAllowed; i++, ap++) {
2302 if (ap->port != 0 && ap->port != sport) {

--- 16 unchanged lines hidden (view full) ---

2319 continue;
2320 }
2321 }
2322#ifdef INET6
2323 else if (ap->a_addr.ss_family == AF_INET6) {
2324 sin6 = (struct sockaddr_in6 *)sa;
2325 a6p = (struct sockaddr_in6 *)&ap->a_addr;
2326 m6p = (struct sockaddr_in6 *)&ap->a_mask;
2285 return (0); /* for safety, should not occur */
2286 dprintf("validate: dgram from IP %s, port %s, name %s;\n",
2287 ip, port, name);
2288 sport = atoi(port);
2289
2290 /* now, walk down the list */
2291 for (i = 0, ap = AllowedPeers; i < NumAllowed; i++, ap++) {
2292 if (ap->port != 0 && ap->port != sport) {

--- 16 unchanged lines hidden (view full) ---

2309 continue;
2310 }
2311 }
2312#ifdef INET6
2313 else if (ap->a_addr.ss_family == AF_INET6) {
2314 sin6 = (struct sockaddr_in6 *)sa;
2315 a6p = (struct sockaddr_in6 *)&ap->a_addr;
2316 m6p = (struct sockaddr_in6 *)&ap->a_mask;
2327#ifdef NI_WITHSCOPEID
2328 if (a6p->sin6_scope_id != 0 &&
2329 sin6->sin6_scope_id != a6p->sin6_scope_id) {
2330 dprintf("rejected in rule %d due to scope mismatch.\n", i);
2331 continue;
2332 }
2317 if (a6p->sin6_scope_id != 0 &&
2318 sin6->sin6_scope_id != a6p->sin6_scope_id) {
2319 dprintf("rejected in rule %d due to scope mismatch.\n", i);
2320 continue;
2321 }
2333#endif
2334 reject = 0;
2335 for (j = 0; j < 16; j += 4) {
2336 if ((*(u_int32_t *)&sin6->sin6_addr.s6_addr[j] & *(u_int32_t *)&m6p->sin6_addr.s6_addr[j])
2337 != *(u_int32_t *)&a6p->sin6_addr.s6_addr[j]) {
2338 ++reject;
2339 break;
2340 }
2341 }

--- 266 unchanged lines hidden ---
2322 reject = 0;
2323 for (j = 0; j < 16; j += 4) {
2324 if ((*(u_int32_t *)&sin6->sin6_addr.s6_addr[j] & *(u_int32_t *)&m6p->sin6_addr.s6_addr[j])
2325 != *(u_int32_t *)&a6p->sin6_addr.s6_addr[j]) {
2326 ++reject;
2327 break;
2328 }
2329 }

--- 266 unchanged lines hidden ---