Print this page
10121 smatch fix for auditstat
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/auditstat/auditstat.c
+++ new/usr/src/cmd/auditstat/auditstat.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 +/*
27 + * Copyright (c) 2018, Joyent, Inc.
28 + */
29 +
26 30 #include "statcommon.h"
27 31
28 32 #include <sys/types.h>
29 33 #include <stdlib.h>
30 34 #include <ctype.h>
31 35 #include <stdio.h>
32 36 #include <bsm/audit.h>
33 37 #include <bsm/libbsm.h>
34 38 #include <unistd.h>
35 39 #include <locale.h>
36 40
37 41 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
38 42 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */
39 43 #endif
40 44
41 45
42 46 /*
43 47 * Display header every HEADER_MOD lines printed
44 48 */
45 49 #define DFLT_HEADER_MOD (20)
46 50 #define ONEK (1024)
47 51
48 52 #define CFLG (0x01)
49 53 #define HFLG (0x02)
50 54 #define IFLG (0x04)
51 55 #define NFLG (0x08)
52 56 #define VFLG (0x10)
53 57
54 58 extern char *optarg;
55 59
56 60 static int count;
57 61 static int flags;
58 62 static int header_mod = DFLT_HEADER_MOD;
59 63 static int interval;
60 64 static uint_t timestamp_fmt = NODATE;
61 65
62 66 static void display_stats();
63 67 static void eauditon();
64 68 static void parse_args();
65 69 static void usage_exit();
66 70 static int strisdigit();
67 71
68 72 int
69 73 main(argc, argv)
70 74 int argc;
71 75 char **argv;
72 76 {
73 77 register int i;
74 78 au_stat_t s;
75 79
76 80 (void) setlocale(LC_ALL, "");
77 81 (void) textdomain(TEXT_DOMAIN);
78 82
79 83 (void) setbuf(stdout, (char *)0);
80 84 (void) setbuf(stderr, (char *)0);
81 85
82 86 parse_args(argc, argv);
83 87
84 88 if (!flags) {
85 89 eauditon(A_GETSTAT, (caddr_t)&s, NULL);
86 90 if (timestamp_fmt != NODATE)
87 91 print_timestamp(timestamp_fmt);
88 92 display_stats(&s, 0);
89 93 exit(0);
90 94 }
91 95
92 96 if (flags & VFLG || flags & NFLG)
93 97 eauditon(A_GETSTAT, (caddr_t)&s, NULL);
94 98
95 99 if (flags & VFLG)
96 100 (void) printf("version = %d\n", s.as_version);
97 101
98 102 if (flags & NFLG)
99 103 (void) printf("number of kernel events = %d\n", s.as_numevent);
100 104
101 105 if (!(flags & IFLG))
102 106 exit(0);
103 107
104 108 /* CSTYLED */
105 109 for (i = 0;; i++) {
106 110 eauditon(A_GETSTAT, (caddr_t)&s, NULL);
107 111 if (timestamp_fmt != NODATE)
108 112 print_timestamp(timestamp_fmt);
109 113 display_stats(&s, i);
110 114 if ((flags & CFLG) && count)
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
111 115 if (i == count - 1)
112 116 break;
113 117 (void) sleep(interval);
114 118 }
115 119
116 120 return (0);
117 121 }
118 122
119 123
120 124 static void
121 -display_stats(s, cnt)
122 -au_stat_t *s;
125 +display_stats(au_stat_t *s, int cnt)
123 126 {
124 127 int offset[12]; /* used to line the header up correctly */
125 128 char buf[512];
126 129
127 130 (void) sprintf(buf,
128 131 "%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u %n%4u%n",
129 132 s->as_generated, &(offset[0]),
130 133 s->as_nonattrib, &(offset[1]),
131 134 s->as_kernel, &(offset[2]),
132 135 s->as_audit, &(offset[3]),
133 136 s->as_auditctl, &(offset[4]),
134 137 s->as_enqueue, &(offset[5]),
135 138 s->as_written, &(offset[6]),
136 139 s->as_wblocked, &(offset[7]),
137 140 s->as_rblocked, &(offset[8]),
138 141 s->as_dropped, &(offset[9]),
139 142 s->as_totalsize / ONEK, &(offset[10]),
140 143 s->as_memused / ONEK, &(offset[11]));
141 144
142 145 /* print a properly aligned header every HEADER_MOD lines */
143 146 if (header_mod && (!cnt || ((timestamp_fmt != NODATE) ?
144 147 !(cnt % (header_mod / 2)) : !(cnt % header_mod)))) {
145 148 (void) printf(
146 149 "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n",
147 150 offset[0] - 1, "gen",
148 151 offset[1] - offset[0] - 1, "nona",
149 152 offset[2] - offset[1] - 1, "kern",
150 153 offset[3] - offset[2] - 1, "aud",
151 154 offset[4] - offset[3] - 1, "ctl",
152 155 offset[5] - offset[4] - 1, "enq",
153 156 offset[6] - offset[5] - 1, "wrtn",
154 157 offset[7] - offset[6] - 1, "wblk",
155 158 offset[8] - offset[7] - 1, "rblk",
156 159 offset[9] - offset[8] - 1, "drop",
157 160 offset[10] - offset[9] - 1, "tot",
158 161 offset[11] - offset[10], "mem");
159 162 }
160 163
161 164 (void) puts(buf);
162 165 }
163 166
164 167
165 168 static void
166 169 eauditon(cmd, data, length)
167 170 int cmd;
168 171 caddr_t data;
169 172 int length;
170 173 {
171 174 if (auditon(cmd, data, length) == -1) {
172 175 perror("auditstat: auditon");
173 176 exit(1);
174 177 }
175 178 }
176 179
177 180
178 181 static void
179 182 parse_args(argc, argv)
180 183 int argc;
181 184 char **argv;
182 185 {
183 186 int c;
184 187
185 188 while ((c = getopt(argc, argv, "c:h:i:vnT:")) != -1) {
186 189 switch (c) {
187 190 case 'c':
188 191 if (flags & CFLG)
189 192 usage_exit();
190 193 flags |= CFLG;
191 194 if (strisdigit(optarg)) {
192 195 (void) fprintf(stderr,
193 196 "auditstat: invalid count specified.\n");
194 197 exit(1);
195 198 }
196 199 count = atoi(optarg);
197 200 break;
198 201 case 'h':
199 202 if (flags & HFLG)
200 203 usage_exit();
201 204 flags |= HFLG;
202 205 if (strisdigit(optarg)) {
203 206 (void) fprintf(stderr,
204 207 "auditstat: invalid header arg specified.\n");
205 208 exit(1);
206 209 }
207 210 header_mod = atoi(optarg);
208 211 break;
209 212 case 'i':
210 213 if (flags & IFLG)
211 214 usage_exit();
212 215 flags |= IFLG;
213 216 if (strisdigit(optarg)) {
214 217 (void) fprintf(stderr,
215 218 "auditstat: invalid interval specified.\n");
216 219 exit(1);
217 220 }
218 221 interval = atoi(optarg);
219 222 break;
220 223 case 'n':
221 224 if (flags & NFLG)
222 225 usage_exit();
223 226 flags |= NFLG;
224 227 break;
225 228 case 'v':
226 229 if (flags & VFLG)
227 230 usage_exit();
228 231 flags |= VFLG;
229 232 break;
230 233 case 'T':
231 234 if (optarg) {
232 235 if (*optarg == 'u')
233 236 timestamp_fmt = UDATE;
234 237 else if (*optarg == 'd')
235 238 timestamp_fmt = DDATE;
236 239 else
237 240 usage_exit();
238 241 } else {
239 242 usage_exit();
240 243 }
241 244 break;
242 245 case '?':
243 246 default:
244 247 usage_exit();
245 248 break;
246 249 }
247 250 }
248 251 }
249 252
250 253
251 254 static void
252 255 usage_exit()
253 256 {
254 257 (void) fprintf(stderr,
255 258 "auditstat: usage: auditstat [-c count] [-h lines] "
256 259 "[-T d|u] [-i interval] [-n] [-v]\n");
257 260 exit(1);
258 261 }
259 262
260 263
261 264 static int
262 265 strisdigit(s)
263 266 char *s;
264 267 {
265 268 for (; *s; s++)
266 269 if (!isdigit(*s))
267 270 return (1);
268 271
269 272 return (0);
270 273 }
↓ open down ↓ |
138 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX