Print this page
patch tsoome-feedback
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/hotplugd/hotplugd_door.c
+++ new/usr/src/cmd/hotplugd/hotplugd_door.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
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 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #include <stdio.h>
28 28 #include <stdlib.h>
29 29 #include <unistd.h>
30 30 #include <fcntl.h>
31 31 #include <errno.h>
32 32 #include <strings.h>
33 33 #include <alloca.h>
34 34 #include <door.h>
35 35 #include <pthread.h>
36 36 #include <synch.h>
37 37 #include <pwd.h>
38 38 #include <auth_list.h>
39 39 #include <auth_attr.h>
40 40 #include <bsm/adt.h>
41 41 #include <bsm/adt_event.h>
42 42 #include <sys/sunddi.h>
43 43 #include <sys/ddi_hp.h>
44 44 #include <libnvpair.h>
45 45 #include <libhotplug.h>
46 46 #include <libhotplug_impl.h>
47 47 #include "hotplugd_impl.h"
48 48
49 49 /*
50 50 * Buffer management for results.
51 51 */
52 52 typedef struct i_buffer {
53 53 uint64_t seqnum;
54 54 char *buffer;
55 55 struct i_buffer *next;
56 56 } i_buffer_t;
57 57
58 58 static uint64_t buffer_seqnum = 1;
59 59 static i_buffer_t *buffer_list = NULL;
60 60 static pthread_mutex_t buffer_lock = PTHREAD_MUTEX_INITIALIZER;
61 61
62 62 /*
63 63 * Door file descriptor.
64 64 */
65 65 static int door_fd = -1;
66 66
67 67 /*
68 68 * Function prototypes.
69 69 */
70 70 static void door_server(void *, char *, size_t, door_desc_t *, uint_t);
71 71 static int check_auth(ucred_t *, const char *);
72 72 static int cmd_getinfo(nvlist_t *, nvlist_t **);
73 73 static int cmd_changestate(nvlist_t *, nvlist_t **);
74 74 static int cmd_private(hp_cmd_t, nvlist_t *, nvlist_t **);
75 75 static void add_buffer(uint64_t, char *);
76 76 static void free_buffer(uint64_t);
77 77 static uint64_t get_seqnum(void);
78 78 static char *state_str(int);
79 79 static int audit_session(ucred_t *, adt_session_data_t **);
80 80 static void audit_changestate(ucred_t *, char *, char *, char *, int, int,
81 81 int);
82 82 static void audit_setprivate(ucred_t *, char *, char *, char *, char *,
83 83 int);
84 84
85 85 /*
86 86 * door_server_init()
87 87 *
88 88 * Create the door file, and initialize the door server.
89 89 */
90 90 boolean_t
91 91 door_server_init(void)
92 92 {
93 93 int fd;
94 94
95 95 /* Create the door file */
96 96 if ((fd = open(HOTPLUGD_DOOR, O_CREAT|O_EXCL|O_RDONLY, 0644)) == -1) {
97 97 if (errno == EEXIST) {
98 98 log_err("Door service is already running.\n");
99 99 } else {
100 100 log_err("Cannot open door file '%s': %s\n",
101 101 HOTPLUGD_DOOR, strerror(errno));
102 102 }
103 103 return (B_FALSE);
104 104 }
105 105 (void) close(fd);
106 106
107 107 /* Initialize the door service */
108 108 if ((door_fd = door_create(door_server, NULL,
109 109 DOOR_REFUSE_DESC | DOOR_NO_CANCEL)) == -1) {
110 110 log_err("Cannot create door service: %s\n", strerror(errno));
111 111 return (B_FALSE);
112 112 }
113 113
114 114 /* Cleanup stale door associations */
115 115 (void) fdetach(HOTPLUGD_DOOR);
116 116
117 117 /* Associate door service with door file */
118 118 if (fattach(door_fd, HOTPLUGD_DOOR) != 0) {
119 119 log_err("Cannot attach to door file '%s': %s\n", HOTPLUGD_DOOR,
120 120 strerror(errno));
121 121 (void) door_revoke(door_fd);
122 122 (void) fdetach(HOTPLUGD_DOOR);
123 123 door_fd = -1;
124 124 return (B_FALSE);
125 125 }
126 126
127 127 return (B_TRUE);
128 128 }
129 129
130 130 /*
131 131 * door_server_fini()
132 132 *
133 133 * Terminate and cleanup the door server.
134 134 */
135 135 void
136 136 door_server_fini(void)
137 137 {
138 138 if (door_fd != -1) {
139 139 (void) door_revoke(door_fd);
140 140 (void) fdetach(HOTPLUGD_DOOR);
141 141 }
142 142
143 143 (void) unlink(HOTPLUGD_DOOR);
144 144 }
145 145
146 146 /*
147 147 * door_server()
148 148 *
149 149 * This routine is the handler which responds to each door call.
150 150 * Each incoming door call is expected to send a packed nvlist
151 151 * of arguments which describe the requested action. And each
152 152 * response is sent back as a packed nvlist of results.
153 153 *
154 154 * Results are always allocated on the heap. A global list of
155 155 * allocated result buffers is managed, and each one is tracked
156 156 * by a unique sequence number. The final step in the protocol
157 157 * is for the caller to send a short response using the sequence
158 158 * number when the buffer can be released.
159 159 */
160 160 /*ARGSUSED*/
161 161 static void
162 162 door_server(void *cookie, char *argp, size_t sz, door_desc_t *dp, uint_t ndesc)
163 163 {
164 164 nvlist_t *args = NULL;
165 165 nvlist_t *results = NULL;
166 166 hp_cmd_t cmd;
167 167 int rv;
168 168
169 169 dprintf("Door call: cookie=%p, argp=%p, sz=%d\n", cookie, (void *)argp,
170 170 sz);
171 171
172 172 /* Special case to free a results buffer */
173 173 if (sz == sizeof (uint64_t)) {
174 174 free_buffer(*(uint64_t *)(uintptr_t)argp);
175 175 (void) door_return(NULL, 0, NULL, 0);
176 176 return;
177 177 }
178 178
179 179 /* Unpack the arguments nvlist */
180 180 if (nvlist_unpack(argp, sz, &args, 0) != 0) {
181 181 log_err("Cannot unpack door arguments.\n");
182 182 rv = EINVAL;
183 183 goto fail;
184 184 }
185 185
186 186 /* Extract the requested command */
187 187 if (nvlist_lookup_int32(args, HPD_CMD, (int32_t *)&cmd) != 0) {
188 188 log_err("Cannot decode door command.\n");
189 189 rv = EINVAL;
190 190 goto fail;
191 191 }
192 192
193 193 /* Implement the command */
194 194 switch (cmd) {
195 195 case HP_CMD_GETINFO:
196 196 rv = cmd_getinfo(args, &results);
197 197 break;
198 198 case HP_CMD_CHANGESTATE:
199 199 rv = cmd_changestate(args, &results);
200 200 break;
201 201 case HP_CMD_SETPRIVATE:
202 202 case HP_CMD_GETPRIVATE:
203 203 rv = cmd_private(cmd, args, &results);
204 204 break;
205 205 default:
206 206 rv = EINVAL;
207 207 break;
208 208 }
209 209
210 210 /* The arguments nvlist is no longer needed */
211 211 nvlist_free(args);
212 212 args = NULL;
213 213
214 214 /*
215 215 * If an nvlist was constructed for the results,
216 216 * then pack the results nvlist and return it.
217 217 */
218 218 if (results != NULL) {
219 219 uint64_t seqnum;
220 220 char *buf = NULL;
221 221 size_t len = 0;
222 222
223 223 /* Add a sequence number to the results */
224 224 seqnum = get_seqnum();
225 225 if (nvlist_add_uint64(results, HPD_SEQNUM, seqnum) != 0) {
226 226 log_err("Cannot add sequence number.\n");
227 227 rv = EFAULT;
228 228 goto fail;
229 229 }
230 230
231 231 /* Pack the results nvlist */
232 232 if (nvlist_pack(results, &buf, &len,
233 233 NV_ENCODE_NATIVE, 0) != 0) {
234 234 log_err("Cannot pack door results.\n");
235 235 rv = EFAULT;
236 236 goto fail;
237 237 }
238 238
239 239 /* Link results buffer into list */
240 240 add_buffer(seqnum, buf);
241 241
242 242 /* The results nvlist is no longer needed */
243 243 nvlist_free(results);
244 244
245 245 /* Return the results */
↓ open down ↓ |
245 lines elided |
↑ open up ↑ |
246 246 (void) door_return(buf, len, NULL, 0);
247 247 return;
248 248 }
249 249
250 250 /* Return result code (when no nvlist) */
251 251 (void) door_return((char *)&rv, sizeof (int), NULL, 0);
252 252 return;
253 253
254 254 fail:
255 255 log_err("Door call failed (%s)\n", strerror(rv));
256 - if (args != NULL)
257 - nvlist_free(args);
258 - if (results != NULL)
259 - nvlist_free(results);
256 + nvlist_free(args);
257 + nvlist_free(results);
260 258 (void) door_return((char *)&rv, sizeof (int), NULL, 0);
261 259 }
262 260
263 261 /*
264 262 * check_auth()
265 263 *
266 264 * Perform an RBAC authorization check.
267 265 */
268 266 static int
269 267 check_auth(ucred_t *ucred, const char *auth)
270 268 {
271 269 struct passwd pwd;
272 270 uid_t euid;
273 271 char buf[MAXPATHLEN];
274 272
275 273 euid = ucred_geteuid(ucred);
276 274
277 275 if ((getpwuid_r(euid, &pwd, buf, sizeof (buf)) == NULL) ||
278 276 (chkauthattr(auth, pwd.pw_name) == 0)) {
279 277 log_info("Unauthorized door call.\n");
280 278 return (-1);
281 279 }
282 280
283 281 return (0);
284 282 }
285 283
286 284 /*
287 285 * cmd_getinfo()
288 286 *
289 287 * Implements the door command to get a hotplug information snapshot.
290 288 */
291 289 static int
292 290 cmd_getinfo(nvlist_t *args, nvlist_t **resultsp)
293 291 {
294 292 hp_node_t root;
295 293 nvlist_t *results;
296 294 char *path;
297 295 char *connection;
298 296 char *buf = NULL;
299 297 size_t len = 0;
300 298 uint_t flags;
301 299 int rv;
302 300
303 301 dprintf("cmd_getinfo:\n");
304 302
305 303 /* Get arguments */
306 304 if (nvlist_lookup_string(args, HPD_PATH, &path) != 0) {
307 305 dprintf("cmd_getinfo: invalid arguments.\n");
308 306 return (EINVAL);
309 307 }
310 308 if (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0)
311 309 connection = NULL;
312 310 if (nvlist_lookup_uint32(args, HPD_FLAGS, (uint32_t *)&flags) != 0)
313 311 flags = 0;
314 312
315 313 /* Get and pack the requested snapshot */
316 314 if ((rv = getinfo(path, connection, flags, &root)) == 0) {
317 315 rv = hp_pack(root, &buf, &len);
318 316 hp_fini(root);
319 317 }
320 318 dprintf("cmd_getinfo: getinfo(): rv = %d, buf = %p.\n", rv,
321 319 (void *)buf);
322 320
323 321 /*
324 322 * If the above failed or there is no snapshot,
325 323 * then only return a status code.
326 324 */
327 325 if (rv != 0)
328 326 return (rv);
329 327 if (buf == NULL)
330 328 return (EFAULT);
331 329
332 330 /* Allocate nvlist for results */
333 331 if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
334 332 dprintf("cmd_getinfo: nvlist_alloc() failed.\n");
335 333 free(buf);
336 334 return (ENOMEM);
337 335 }
338 336
339 337 /* Add snapshot and successful status to results */
340 338 if ((nvlist_add_int32(results, HPD_STATUS, 0) != 0) ||
341 339 (nvlist_add_byte_array(results, HPD_INFO,
342 340 (uchar_t *)buf, len) != 0)) {
343 341 dprintf("cmd_getinfo: nvlist add failure.\n");
344 342 nvlist_free(results);
345 343 free(buf);
346 344 return (ENOMEM);
347 345 }
348 346
349 347 /* Packed snapshot no longer needed */
350 348 free(buf);
351 349
352 350 /* Success */
353 351 *resultsp = results;
354 352 return (0);
355 353 }
356 354
357 355 /*
358 356 * cmd_changestate()
359 357 *
360 358 * Implements the door command to initate a state change operation.
361 359 *
362 360 * NOTE: requires 'modify' authorization.
363 361 */
364 362 static int
365 363 cmd_changestate(nvlist_t *args, nvlist_t **resultsp)
366 364 {
367 365 hp_node_t root = NULL;
368 366 nvlist_t *results = NULL;
369 367 char *path, *connection;
370 368 ucred_t *uc = NULL;
371 369 uint_t flags;
372 370 int rv, state, old_state, status;
373 371
374 372 dprintf("cmd_changestate:\n");
375 373
376 374 /* Get arguments */
377 375 if ((nvlist_lookup_string(args, HPD_PATH, &path) != 0) ||
378 376 (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0) ||
379 377 (nvlist_lookup_int32(args, HPD_STATE, &state) != 0)) {
380 378 dprintf("cmd_changestate: invalid arguments.\n");
381 379 return (EINVAL);
382 380 }
383 381 if (nvlist_lookup_uint32(args, HPD_FLAGS, (uint32_t *)&flags) != 0)
384 382 flags = 0;
385 383
386 384 /* Get caller's credentials */
387 385 if (door_ucred(&uc) != 0) {
388 386 log_err("Cannot get door credentials (%s)\n", strerror(errno));
389 387 return (EACCES);
390 388 }
391 389
392 390 /* Check authorization */
393 391 if (check_auth(uc, HP_MODIFY_AUTH) != 0) {
394 392 dprintf("cmd_changestate: access denied.\n");
395 393 audit_changestate(uc, HP_MODIFY_AUTH, path, connection,
396 394 state, -1, ADT_FAIL_VALUE_AUTH);
397 395 ucred_free(uc);
398 396 return (EACCES);
399 397 }
400 398
401 399 /* Perform the state change operation */
402 400 status = changestate(path, connection, state, flags, &old_state, &root);
403 401 dprintf("cmd_changestate: changestate() == %d\n", status);
404 402
405 403 /* Audit the operation */
406 404 audit_changestate(uc, HP_MODIFY_AUTH, path, connection, state,
407 405 old_state, status);
408 406
409 407 /* Caller's credentials no longer needed */
410 408 ucred_free(uc);
411 409
412 410 /*
413 411 * Pack the results into an nvlist if there is an error snapshot.
414 412 *
415 413 * If any error occurs while packing the results, the original
416 414 * error code from changestate() above is still returned.
417 415 */
418 416 if (root != NULL) {
419 417 char *buf = NULL;
420 418 size_t len = 0;
421 419
422 420 dprintf("cmd_changestate: results nvlist required.\n");
423 421
424 422 /* Pack and discard the error snapshot */
425 423 rv = hp_pack(root, &buf, &len);
426 424 hp_fini(root);
427 425 if (rv != 0) {
428 426 dprintf("cmd_changestate: hp_pack() failed (%s).\n",
429 427 strerror(rv));
430 428 return (status);
431 429 }
432 430
433 431 /* Allocate nvlist for results */
434 432 if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
435 433 dprintf("cmd_changestate: nvlist_alloc() failed.\n");
436 434 free(buf);
437 435 return (status);
438 436 }
439 437
440 438 /* Add the results into the nvlist */
441 439 if ((nvlist_add_int32(results, HPD_STATUS, status) != 0) ||
442 440 (nvlist_add_byte_array(results, HPD_INFO, (uchar_t *)buf,
443 441 len) != 0)) {
444 442 dprintf("cmd_changestate: nvlist add failed.\n");
445 443 nvlist_free(results);
446 444 free(buf);
447 445 return (status);
448 446 }
449 447
450 448 *resultsp = results;
451 449 }
452 450
453 451 return (status);
454 452 }
455 453
456 454 /*
457 455 * cmd_private()
458 456 *
459 457 * Implementation of the door command to set or get bus private options.
460 458 *
461 459 * NOTE: requires 'modify' authorization for the 'set' command.
462 460 */
463 461 static int
464 462 cmd_private(hp_cmd_t cmd, nvlist_t *args, nvlist_t **resultsp)
465 463 {
466 464 nvlist_t *results = NULL;
467 465 ucred_t *uc = NULL;
468 466 char *path, *connection, *options;
469 467 char *values = NULL;
470 468 int status;
471 469
472 470 dprintf("cmd_private:\n");
473 471
474 472 /* Get caller's credentials */
475 473 if ((cmd == HP_CMD_SETPRIVATE) && (door_ucred(&uc) != 0)) {
476 474 log_err("Cannot get door credentials (%s)\n", strerror(errno));
477 475 return (EACCES);
478 476 }
479 477
480 478 /* Get arguments */
481 479 if ((nvlist_lookup_string(args, HPD_PATH, &path) != 0) ||
482 480 (nvlist_lookup_string(args, HPD_CONNECTION, &connection) != 0) ||
483 481 (nvlist_lookup_string(args, HPD_OPTIONS, &options) != 0)) {
484 482 dprintf("cmd_private: invalid arguments.\n");
485 483 return (EINVAL);
486 484 }
487 485
488 486 /* Check authorization */
489 487 if ((cmd == HP_CMD_SETPRIVATE) &&
490 488 (check_auth(uc, HP_MODIFY_AUTH) != 0)) {
491 489 dprintf("cmd_private: access denied.\n");
492 490 audit_setprivate(uc, HP_MODIFY_AUTH, path, connection, options,
493 491 ADT_FAIL_VALUE_AUTH);
494 492 ucred_free(uc);
495 493 return (EACCES);
496 494 }
497 495
498 496 /* Perform the operation */
499 497 status = private_options(path, connection, cmd, options, &values);
500 498 dprintf("cmd_private: private_options() == %d\n", status);
501 499
502 500 /* Audit the operation */
503 501 if (cmd == HP_CMD_SETPRIVATE) {
504 502 audit_setprivate(uc, HP_MODIFY_AUTH, path, connection, options,
505 503 status);
506 504 ucred_free(uc);
507 505 }
508 506
509 507 /* Construct an nvlist if values were returned */
510 508 if (values != NULL) {
511 509
512 510 /* Allocate nvlist for results */
513 511 if (nvlist_alloc(&results, NV_UNIQUE_NAME_TYPE, 0) != 0) {
514 512 dprintf("cmd_private: nvlist_alloc() failed.\n");
515 513 free(values);
516 514 return (ENOMEM);
517 515 }
518 516
519 517 /* Add values and status to the results */
520 518 if ((nvlist_add_int32(results, HPD_STATUS, status) != 0) ||
521 519 (nvlist_add_string(results, HPD_OPTIONS, values) != 0)) {
522 520 dprintf("cmd_private: nvlist add failed.\n");
523 521 nvlist_free(results);
524 522 free(values);
525 523 return (ENOMEM);
526 524 }
527 525
528 526 /* The values string is no longer needed */
529 527 free(values);
530 528
531 529 *resultsp = results;
532 530 }
533 531
534 532 return (status);
535 533 }
536 534
537 535 /*
538 536 * get_seqnum()
539 537 *
540 538 * Allocate the next unique sequence number for a results buffer.
541 539 */
542 540 static uint64_t
543 541 get_seqnum(void)
544 542 {
545 543 uint64_t seqnum;
546 544
547 545 (void) pthread_mutex_lock(&buffer_lock);
548 546
549 547 seqnum = buffer_seqnum++;
550 548
551 549 (void) pthread_mutex_unlock(&buffer_lock);
552 550
553 551 return (seqnum);
554 552 }
555 553
556 554 /*
557 555 * add_buffer()
558 556 *
559 557 * Link a results buffer into the list containing all buffers.
560 558 */
561 559 static void
562 560 add_buffer(uint64_t seqnum, char *buf)
563 561 {
564 562 i_buffer_t *node;
565 563
566 564 if ((node = (i_buffer_t *)malloc(sizeof (i_buffer_t))) == NULL) {
567 565 /* The consequence is a memory leak. */
568 566 log_err("Cannot allocate results buffer: %s\n",
569 567 strerror(errno));
570 568 return;
571 569 }
572 570
573 571 node->seqnum = seqnum;
574 572 node->buffer = buf;
575 573
576 574 (void) pthread_mutex_lock(&buffer_lock);
577 575
578 576 node->next = buffer_list;
579 577 buffer_list = node;
580 578
581 579 (void) pthread_mutex_unlock(&buffer_lock);
582 580 }
583 581
584 582 /*
585 583 * free_buffer()
586 584 *
587 585 * Remove a results buffer from the list containing all buffers.
588 586 */
589 587 static void
590 588 free_buffer(uint64_t seqnum)
591 589 {
592 590 i_buffer_t *node, *prev;
593 591
594 592 (void) pthread_mutex_lock(&buffer_lock);
595 593
596 594 prev = NULL;
597 595 node = buffer_list;
598 596
599 597 while (node) {
600 598 if (node->seqnum == seqnum) {
601 599 dprintf("Free buffer %lld\n", seqnum);
602 600 if (prev) {
603 601 prev->next = node->next;
604 602 } else {
605 603 buffer_list = node->next;
606 604 }
607 605 free(node->buffer);
608 606 free(node);
609 607 break;
610 608 }
611 609 prev = node;
612 610 node = node->next;
613 611 }
614 612
615 613 (void) pthread_mutex_unlock(&buffer_lock);
616 614 }
617 615
618 616 /*
619 617 * audit_session()
620 618 *
621 619 * Initialize an audit session.
622 620 */
623 621 static int
624 622 audit_session(ucred_t *ucred, adt_session_data_t **sessionp)
625 623 {
626 624 adt_session_data_t *session;
627 625
628 626 if (adt_start_session(&session, NULL, 0) != 0) {
629 627 log_err("Cannot start audit session.\n");
630 628 return (-1);
631 629 }
632 630
633 631 if (adt_set_from_ucred(session, ucred, ADT_NEW) != 0) {
634 632 log_err("Cannot set audit session from ucred.\n");
635 633 (void) adt_end_session(session);
636 634 return (-1);
637 635 }
638 636
639 637 *sessionp = session;
640 638 return (0);
641 639 }
642 640
643 641 /*
644 642 * audit_changestate()
645 643 *
646 644 * Audit a 'changestate' door command.
647 645 */
648 646 static void
649 647 audit_changestate(ucred_t *ucred, char *auth, char *path, char *connection,
650 648 int new_state, int old_state, int result)
651 649 {
652 650 adt_session_data_t *session;
653 651 adt_event_data_t *event;
654 652 int pass_fail, fail_reason;
655 653
656 654 if (audit_session(ucred, &session) != 0)
657 655 return;
658 656
659 657 if ((event = adt_alloc_event(session, ADT_hotplug_state)) == NULL) {
660 658 (void) adt_end_session(session);
661 659 return;
662 660 }
663 661
664 662 if (result == 0) {
665 663 pass_fail = ADT_SUCCESS;
666 664 fail_reason = ADT_SUCCESS;
667 665 } else {
668 666 pass_fail = ADT_FAILURE;
669 667 fail_reason = result;
670 668 }
671 669
672 670 event->adt_hotplug_state.auth_used = auth;
673 671 event->adt_hotplug_state.device_path = path;
674 672 event->adt_hotplug_state.connection = connection;
675 673 event->adt_hotplug_state.new_state = state_str(new_state);
676 674 event->adt_hotplug_state.old_state = state_str(old_state);
677 675
678 676 /* Put the event */
679 677 if (adt_put_event(event, pass_fail, fail_reason) != 0)
680 678 log_err("Cannot put audit event.\n");
681 679
682 680 adt_free_event(event);
683 681 (void) adt_end_session(session);
684 682 }
685 683
686 684 /*
687 685 * audit_setprivate()
688 686 *
689 687 * Audit a 'set private' door command.
690 688 */
691 689 static void
692 690 audit_setprivate(ucred_t *ucred, char *auth, char *path, char *connection,
693 691 char *options, int result)
694 692 {
695 693 adt_session_data_t *session;
696 694 adt_event_data_t *event;
697 695 int pass_fail, fail_reason;
698 696
699 697 if (audit_session(ucred, &session) != 0)
700 698 return;
701 699
702 700 if ((event = adt_alloc_event(session, ADT_hotplug_set)) == NULL) {
703 701 (void) adt_end_session(session);
704 702 return;
705 703 }
706 704
707 705 if (result == 0) {
708 706 pass_fail = ADT_SUCCESS;
709 707 fail_reason = ADT_SUCCESS;
710 708 } else {
711 709 pass_fail = ADT_FAILURE;
712 710 fail_reason = result;
713 711 }
714 712
715 713 event->adt_hotplug_set.auth_used = auth;
716 714 event->adt_hotplug_set.device_path = path;
717 715 event->adt_hotplug_set.connection = connection;
718 716 event->adt_hotplug_set.options = options;
719 717
720 718 /* Put the event */
721 719 if (adt_put_event(event, pass_fail, fail_reason) != 0)
722 720 log_err("Cannot put audit event.\n");
723 721
724 722 adt_free_event(event);
725 723 (void) adt_end_session(session);
726 724 }
727 725
728 726 /*
729 727 * state_str()
730 728 *
731 729 * Convert a state from integer to string.
732 730 */
733 731 static char *
734 732 state_str(int state)
735 733 {
736 734 switch (state) {
737 735 case DDI_HP_CN_STATE_EMPTY:
738 736 return ("EMPTY");
739 737 case DDI_HP_CN_STATE_PRESENT:
740 738 return ("PRESENT");
741 739 case DDI_HP_CN_STATE_POWERED:
742 740 return ("POWERED");
743 741 case DDI_HP_CN_STATE_ENABLED:
744 742 return ("ENABLED");
745 743 case DDI_HP_CN_STATE_PORT_EMPTY:
746 744 return ("PORT-EMPTY");
747 745 case DDI_HP_CN_STATE_PORT_PRESENT:
748 746 return ("PORT-PRESENT");
749 747 case DDI_HP_CN_STATE_OFFLINE:
750 748 return ("OFFLINE");
751 749 case DDI_HP_CN_STATE_ATTACHED:
752 750 return ("ATTACHED");
753 751 case DDI_HP_CN_STATE_MAINTENANCE:
754 752 return ("MAINTENANCE");
755 753 case DDI_HP_CN_STATE_ONLINE:
756 754 return ("ONLINE");
757 755 default:
758 756 return ("UNKNOWN");
759 757 }
760 758 }
↓ open down ↓ |
491 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX