xref: /titanic_51/usr/src/lib/libbsm/common/audit_at.c (revision 5a7763bf3e9db4cfe6cb523b096cb74af71e3793)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/systeminfo.h>
31 #include <bsm/audit.h>
32 #include <bsm/libbsm.h>
33 #include <bsm/audit_uevents.h>
34 #include <bsm/audit_private.h>
35 #include <unistd.h>
36 #include <stdlib.h>
37 #include <string.h>
38 
39 #include <locale.h>
40 #include "generic.h"
41 
42 #define	AUDIT_AT_TEXTBUF	256
43 static char textbuf[AUDIT_AT_TEXTBUF];
44 
45 int
46 audit_at_create(char *path, int sorf)
47 {
48 	int r = 0;
49 
50 	if (cannot_audit(0)) {
51 		return (0);
52 	} else {
53 		char *anc_name;
54 		auditinfo_addr_t ai;
55 
56 		if (getaudit_addr(&ai, sizeof (ai))) {
57 			return (-1);
58 		}
59 
60 		/*
61 		 * create an ancilary file if audit characteristics exist
62 		 */
63 
64 		anc_name = audit_cron_make_anc_name(path);
65 		if (anc_name == NULL)
66 			r = -1;
67 		else if (audit_crontab_process_not_audited())
68 			free(anc_name);
69 		else {
70 			r = audit_cron_setinfo(anc_name, &ai);
71 			free(anc_name);
72 		}
73 
74 		aug_init();
75 		aug_save_auid(ai.ai_auid);
76 		aug_save_euid(geteuid());
77 		aug_save_egid(getegid());
78 		aug_save_uid(getuid());
79 		aug_save_gid(getgid());
80 		aug_save_pid(getpid());
81 		aug_save_asid(ai.ai_asid);
82 		aug_save_tid_ex(ai.ai_termid.at_port, ai.ai_termid.at_addr,
83 			ai.ai_termid.at_type);
84 
85 		aug_save_path(path);
86 		aug_save_event(AUE_at_create);
87 		aug_save_sorf(sorf);
88 
89 		if (aug_audit() != 0)
90 			return (-1);
91 
92 		return (r);
93 	}
94 }
95 
96 int
97 audit_at_delete(char *name, char *path, int sorf)
98 {
99 	int r = 0, err = 0;
100 	char full_path[PATH_MAX];
101 
102 	if (cannot_audit(0))
103 		return (0);
104 
105 	if (path != NULL) {
106 		if (strlen(path) + strlen(name) + 2 > PATH_MAX)
107 			r = -2;		/* bad at-job name */
108 		else {
109 			(void) strcat(strcat(strcpy(full_path, path), "/"),
110 			    name);
111 			name = full_path;
112 		}
113 	}
114 
115 	if (sorf == 0) {
116 		char *anc_name;
117 		anc_name = audit_cron_make_anc_name(name);
118 		r = unlink(anc_name);
119 		if (r == -1)
120 			err = errno;
121 		free(anc_name);
122 	}
123 
124 	aug_init();
125 	(void) aug_save_me();
126 	if (r == -1) {
127 		(void) snprintf(textbuf, sizeof (textbuf),
128 			dgettext(bsm_dom, "ancillary file: %s"),
129 			strerror(err));
130 		aug_save_text(textbuf);
131 	} else if (r == -2) {
132 		aug_save_text(
133 			dgettext(bsm_dom, "bad format of at-job name"));
134 	}
135 
136 	aug_save_path(name);
137 	aug_save_event(AUE_at_delete);
138 	aug_save_sorf(sorf);
139 
140 	if (aug_audit() != 0)
141 		return (-1);
142 	return (r);
143 }
144