source: branches/samhain-2_2-branch/src/sh_err_syslog.c@ 163

Last change on this file since 163 was 22, checked in by rainer, 19 years ago

Minor code revisions.

File size: 5.3 KB
Line 
1/* SAMHAIN file system integrity testing */
2/* Copyright (C) 2000 Rainer Wichmann */
3/* */
4/* This program is free software; you can redistribute it */
5/* and/or modify */
6/* it under the terms of the GNU General Public License as */
7/* published by */
8/* the Free Software Foundation; either version 2 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* This program is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14/* GNU General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU General Public License */
17/* along with this program; if not, write to the Free Software */
18/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#include "config_xor.h"
21
22#include <syslog.h>
23#include <stdio.h>
24#include <string.h>
25
26#include "samhain.h"
27#include "sh_error.h"
28
29#undef FIL__
30#define FIL__ _("sh_err_syslog.c")
31
32typedef struct log_fac_struct {
33 char * name;
34 int facility;
35} logfct;
36
37static logfct fct_tab[] = {
38#ifdef LOG_AUTH
39 { N_("LOG_AUTH"), LOG_AUTH },
40#endif
41#ifdef LOG_AUTHPRIV
42 { N_("LOG_AUTHPRIV"), LOG_AUTHPRIV },
43#endif
44#ifdef LOG_CRON
45 { N_("LOG_CRON"), LOG_CRON },
46#endif
47#ifdef LOG_DAEMON
48 { N_("LOG_DAEMON"), LOG_DAEMON },
49#endif
50#ifdef LOG_FTP
51 { N_("LOG_FTP"), LOG_FTP },
52#endif
53#ifdef LOG_KERN
54 { N_("LOG_KERN"), LOG_KERN },
55#endif
56#ifdef LOG_LOCAL0
57 { N_("LOG_LOCAL0"), LOG_LOCAL0 },
58#endif
59#ifdef LOG_LOCAL1
60 { N_("LOG_LOCAL1"), LOG_LOCAL1 },
61#endif
62#ifdef LOG_LOCAL2
63 { N_("LOG_LOCAL2"), LOG_LOCAL2 },
64#endif
65#ifdef LOG_LOCAL3
66 { N_("LOG_LOCAL3"), LOG_LOCAL3 },
67#endif
68#ifdef LOG_LOCAL4
69 { N_("LOG_LOCAL4"), LOG_LOCAL4 },
70#endif
71#ifdef LOG_LOCAL5
72 { N_("LOG_LOCAL5"), LOG_LOCAL5 },
73#endif
74#ifdef LOG_LOCAL6
75 { N_("LOG_LOCAL6"), LOG_LOCAL6 },
76#endif
77#ifdef LOG_LOCAL7
78 { N_("LOG_LOCAL7"), LOG_LOCAL7 },
79#endif
80#ifdef LOG_LPR
81 { N_("LOG_LPR"), LOG_LPR },
82#endif
83#ifdef LOG_MAIL
84 { N_("LOG_MAIL"), LOG_MAIL },
85#endif
86#ifdef LOG_NEWS
87 { N_("LOG_NEWS"), LOG_NEWS },
88#endif
89#ifdef LOG_SYSLOG
90 { N_("LOG_SYSLOG"), LOG_SYSLOG },
91#endif
92#ifdef LOG_USER
93 { N_("LOG_USER"), LOG_USER },
94#endif
95#ifdef LOG_UUCP
96 { N_("LOG_UUCP"), LOG_UUCP },
97#endif
98 { NULL, -1 }
99};
100
101#ifdef LOG_AUTHPRIV
102static int my_syslog_facility = LOG_AUTHPRIV;
103#else
104/*@-unrecog@*/
105static int my_syslog_facility = LOG_AUTH;
106/*@+unrecog@*/
107#endif
108
109
110/* set syslog facility
111 */
112int sh_log_set_facility (const char * c)
113{
114 int loop = 0;
115 SL_ENTER(_("sh_log_set_facility"));
116
117 if (c == NULL)
118 SL_RETURN(-1, _("sh_log_set_facility"));
119
120 while (fct_tab[loop].name != NULL)
121 {
122 if (0 == strcmp ( _(fct_tab[loop].name), c))
123 {
124 my_syslog_facility = fct_tab[loop].facility;
125 SL_RETURN(0, _("sh_log_set_facility"));
126 }
127 ++loop;
128 }
129
130 SL_RETURN(-1, _("sh_log_set_facility"));
131}
132
133
134
135/* syslog error message
136 */
137int sh_log_syslog (int severity, /*@null@*/char *errmsg)
138{
139 int priority;
140 size_t len;
141 size_t i;
142 char store;
143 char * p;
144
145 static int init = 0;
146
147 SL_ENTER(_("sh_log_syslog"));
148
149 ASSERT_RET((errmsg != NULL), _("errmsg != NULL"), 0);
150
151 /*@-unrecog@*/
152 if (severity == SH_ERR_ALL) priority = LOG_DEBUG;
153 else if (severity == SH_ERR_INFO) priority = LOG_INFO;
154 else if (severity == SH_ERR_NOTICE) priority = LOG_NOTICE;
155 else if (severity == SH_ERR_WARN) priority = LOG_WARNING;
156 else if (severity == SH_ERR_STAMP) priority = LOG_ERR;
157 else if (severity == SH_ERR_ERR) priority = LOG_ERR;
158 else if (severity == SH_ERR_SEVERE) priority = LOG_CRIT;
159 else if (severity == SH_ERR_FATAL) priority = LOG_ALERT;
160 else priority = LOG_DEBUG;
161 /*@+unrecog@*/
162
163#ifndef LOG_PID
164#define LOG_PID 0
165#endif
166
167 if (init == 0)
168 {
169 /*@-unrecog@*/
170 openlog (sh.prg_name, LOG_PID, my_syslog_facility);
171 /*@+unrecog@*/
172 init = 1;
173 }
174
175 /* --- Limit the message size. ---
176 */
177 len = sl_strlen(errmsg);
178 if (len < 960)
179 {
180 /*@-unrecog@*/
181 syslog (priority, "%s", errmsg);
182 /*@+unrecog@*/
183 }
184 else
185 {
186 i = 960;
187 p = errmsg;
188
189 while (i < len)
190 {
191 store = errmsg[i];
192 errmsg[i] = '\0';
193 /*@-unrecog@*/
194 syslog (priority, "%s", p);
195 /*@+unrecog@*/
196 errmsg[i] = store;
197 p = &errmsg[i];
198 i += 960;
199 }
200 if (i != len)
201 {
202 /*@-unrecog@*/
203 syslog (priority, "%s", p);
204 /*@+unrecog@*/
205 }
206 }
207
208 /* Solaris does not recover if a closeall() closes the
209 * syslog file descriptor, so close it here.
210 */
211 /*@-unrecog@*/
212 closelog();
213 /*@+unrecog@*/
214 init = 0;
215 SL_RETURN(0, _("sh_log_syslog"));
216}
217
218
219
Note: See TracBrowser for help on using the repository browser.