0
|
1 /* Distributed Checksum Clearinghouse |
|
2 * |
|
3 * Copyright (c) 2008 by Rhyolite Software, LLC |
|
4 * |
|
5 * This agreement is not applicable to any entity which sells anti-spam |
|
6 * solutions to others or provides an anti-spam solution as part of a |
|
7 * security solution sold to other entities, or to a private network |
|
8 * which employs the DCC or uses data provided by operation of the DCC |
|
9 * but does not provide corresponding data to other users. |
|
10 * |
|
11 * Permission to use, copy, modify, and distribute this software without |
|
12 * changes for any purpose with or without fee is hereby granted, provided |
|
13 * that the above copyright notice and this permission notice appear in all |
|
14 * copies and any distributed versions or copies are either unchanged |
|
15 * or not called anything similar to "DCC" or "Distributed Checksum |
|
16 * Clearinghouse". |
|
17 * |
|
18 * Parties not eligible to receive a license under this agreement can |
|
19 * obtain a commercial license to use DCC by contacting Rhyolite Software |
|
20 * at sales@rhyolite.com. |
|
21 * |
|
22 * A commercial license would be for Distributed Checksum and Reputation |
|
23 * Clearinghouse software. That software includes additional features. This |
|
24 * free license for Distributed ChecksumClearinghouse Software does not in any |
|
25 * way grant permision to use Distributed Checksum and Reputation Clearinghouse |
|
26 * software |
|
27 * |
|
28 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL |
|
29 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES |
|
30 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC |
|
31 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES |
|
32 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
|
33 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, |
|
34 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS |
|
35 * SOFTWARE. |
|
36 * |
|
37 * Rhyolite Software DCC 1.3.103-1.19 $Revision$ |
|
38 */ |
|
39 |
|
40 #include "dcc_clnt.h" |
|
41 #include "dcc_heap_debug.h" |
|
42 #include <syslog.h> |
|
43 |
|
44 |
|
45 static int |
|
46 parse_level(const char *level) |
|
47 { |
|
48 static struct { |
|
49 const char *str; |
|
50 int level; |
|
51 } level_tbl[] = { |
|
52 {"EMERG", LOG_EMERG}, |
|
53 {"ALERT", LOG_ALERT}, |
|
54 {"CRIT", LOG_CRIT}, |
|
55 {"ERR", LOG_ERR}, |
|
56 {"WARNING", LOG_WARNING}, |
|
57 {"NOTICE", LOG_NOTICE}, |
|
58 {"INFO", LOG_INFO}, |
|
59 {"DEBUG", LOG_DEBUG}, |
|
60 }; |
|
61 int i; |
|
62 |
|
63 for (i = 0; i < DIM(level_tbl); ++i) { |
|
64 if (!strcasecmp(level, level_tbl[i].str)) |
|
65 return level_tbl[i].level; |
|
66 } |
|
67 return -1; |
|
68 } |
|
69 |
|
70 |
|
71 |
|
72 static int |
|
73 parse_facility(const char *facility) |
|
74 { |
|
75 static struct { |
|
76 const char *str; |
|
77 int facility; |
|
78 } facility_tbl[] = { |
|
79 {"AUTH", LOG_AUTH}, |
|
80 #ifdef LOG_AUTHPRIV |
|
81 {"AUTHPRIV",LOG_AUTHPRIV}, |
|
82 #endif |
|
83 {"CRON", LOG_CRON}, |
|
84 {"DAEMON", LOG_DAEMON}, |
|
85 #ifdef LOG_FTP |
|
86 {"FTP", LOG_FTP}, |
|
87 #endif |
|
88 {"KERN", LOG_KERN}, |
|
89 {"LPR", LOG_LPR}, |
|
90 {"MAIL", LOG_MAIL}, |
|
91 {"NEWS", LOG_NEWS}, |
|
92 {"USER", LOG_USER}, |
|
93 {"UUCP", LOG_UUCP}, |
|
94 {"LOCAL0", LOG_LOCAL0}, |
|
95 {"LOCAL1", LOG_LOCAL1}, |
|
96 {"LOCAL2", LOG_LOCAL2}, |
|
97 {"LOCAL3", LOG_LOCAL3}, |
|
98 {"LOCAL4", LOG_LOCAL4}, |
|
99 {"LOCAL5", LOG_LOCAL5}, |
|
100 {"LOCAL6", LOG_LOCAL6}, |
|
101 {"LOCAL7", LOG_LOCAL7}, |
|
102 }; |
|
103 int i; |
|
104 |
|
105 for (i = 0; i < DIM(facility_tbl); ++i) { |
|
106 if (!strcasecmp(facility, facility_tbl[i].str)) |
|
107 return facility_tbl[i].facility; |
|
108 } |
|
109 return -1; |
|
110 } |
|
111 |
|
112 |
|
113 |
|
114 u_char |
|
115 dcc_parse_log_opt(const char *arg) |
|
116 { |
|
117 char *duparg, *facility, *level; |
|
118 int priority, *resultp; |
|
119 |
|
120 if (!LITCMP(arg, "off")) { |
|
121 dcc_no_syslog = 1; |
|
122 return 1; |
|
123 } |
|
124 |
|
125 duparg = dcc_strdup(arg); |
|
126 facility = strpbrk(duparg, ".,"); |
|
127 if (!facility) { |
|
128 dcc_error_msg("missing syslog facility in \"-L %s\"", arg); |
|
129 dcc_free(duparg); |
|
130 return 0; |
|
131 } |
|
132 *facility++ = '\0'; |
|
133 |
|
134 if (!strcasecmp(duparg, "info")) { |
|
135 resultp = &dcc_trace_priority; |
|
136 } else if (!strcasecmp(duparg, "error")) { |
|
137 resultp = &dcc_error_priority; |
|
138 } else { |
|
139 dcc_error_msg("\"%s\" in \"-L %s\"" |
|
140 " is neither \"info\" nor \"error\"", |
|
141 duparg,arg); |
|
142 dcc_free(duparg); |
|
143 return 0; |
|
144 } |
|
145 |
|
146 level = strpbrk(facility, ".,"); |
|
147 if (!level) { |
|
148 dcc_error_msg("missing syslog level in \"-L %s\"", arg); |
|
149 dcc_free(duparg); |
|
150 return 0; |
|
151 } |
|
152 *level++ = '\0'; |
|
153 |
|
154 /* allow both level.facility and facility.level */ |
|
155 priority = parse_facility(facility); |
|
156 if (priority >= 0) { |
|
157 priority |= parse_level(level); |
|
158 } else { |
|
159 priority = parse_facility(level); |
|
160 if (priority < 0) { |
|
161 dcc_error_msg("unrecognized facility in \"%s\"", arg); |
|
162 dcc_free(duparg); |
|
163 return 0; |
|
164 } |
|
165 priority |= parse_level(facility); |
|
166 } |
|
167 if (priority < 0) { |
|
168 dcc_error_msg("unrecognized level in \"%s\"", arg); |
|
169 dcc_free(duparg); |
|
170 return 0; |
|
171 } |
|
172 |
|
173 *resultp = priority; |
|
174 dcc_free(duparg); |
|
175 return 1; |
|
176 } |