]> granicus.if.org Git - shadow/blob - libmisc/cleanup_group.c
* libmisc/failure.c: Replace HAVE_UTMPX_H by USE_UTMPX.
[shadow] / libmisc / cleanup_group.c
1 /*
2  * Copyright (c) 2008       , Nicolas François
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the copyright holders or contributors may not be used to
14  *    endorse or promote products derived from this software without
15  *    specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
21  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <config.h>
31
32 #include <assert.h>
33 #include <stdio.h>
34
35 #include "defines.h"
36 #include "groupio.h"
37 #include "sgroupio.h"
38 #include "prototypes.h"
39
40 /*
41  * cleanup_report_add_group - Report failure to add a group to the system
42  *
43  * It should be registered when it is decided to add a group to the system.
44  */
45 void cleanup_report_add_group (void *group_name)
46 {
47         const char *name = (const char *)group_name;
48
49         SYSLOG ((LOG_ERR, "failed to add group %s", name));
50 #ifdef WITH_AUDIT
51         audit_logger (AUDIT_ADD_GROUP, Prog,
52                       "",
53                       name, AUDIT_NO_ID,
54                       SHADOW_AUDIT_FAILURE);
55 #endif
56 }
57
58 /*
59  * cleanup_report_del_group - Report failure to remove a group from the system
60  *
61  * It should be registered when it is decided to remove a group from the system.
62  */
63 void cleanup_report_del_group (void *group_name)
64 {
65         const char *name = (const char *)group_name;
66
67         SYSLOG ((LOG_ERR, "failed to remove group %s", name));
68 #ifdef WITH_AUDIT
69         audit_logger (AUDIT_DEL_GROUP, Prog,
70                       "",
71                       name, AUDIT_NO_ID,
72                       SHADOW_AUDIT_FAILURE);
73 #endif
74 }
75
76 void cleanup_report_mod_group (void *cleanup_info)
77 {
78         const struct cleanup_info_mod *info;
79         info = (const struct cleanup_info_mod *)cleanup_info;
80
81         SYSLOG ((LOG_ERR,
82                  "failed to change %s (%s)",
83                  gr_dbname (),
84                  info->action));
85 #ifdef WITH_AUDIT
86         audit_logger (AUDIT_USER_ACCT, Prog,
87                       info->audit_msg,
88                       info->name, AUDIT_NO_ID,
89                       SHADOW_AUDIT_FAILURE);
90 #endif
91 }
92
93 #ifdef SHADOWGRP
94 void cleanup_report_mod_gshadow (void *cleanup_info)
95 {
96         const struct cleanup_info_mod *info;
97         info = (const struct cleanup_info_mod *)cleanup_info;
98
99         SYSLOG ((LOG_ERR,
100                  "failed to change %s (%s)",
101                  sgr_dbname (),
102                  info->action));
103 #ifdef WITH_AUDIT
104         audit_logger (AUDIT_USER_ACCT, Prog,
105                       info->audit_msg,
106                       info->name, AUDIT_NO_ID,
107                       SHADOW_AUDIT_FAILURE);
108 #endif
109 }
110 #endif
111
112 /*
113  * cleanup_report_add_group_group - Report failure to add a group to group
114  *
115  * It should be registered when it is decided to add a group to the
116  * group database.
117  */
118 void cleanup_report_add_group_group (void *group_name)
119 {
120         const char *name = (const char *)group_name;
121
122         SYSLOG ((LOG_ERR, "failed to add group %s to %s", name, gr_dbname ()));
123 #ifdef WITH_AUDIT
124         audit_logger (AUDIT_ADD_GROUP, Prog,
125                       "adding group to /etc/group",
126                       name, AUDIT_NO_ID,
127                       SHADOW_AUDIT_FAILURE);
128 #endif
129 }
130
131 #ifdef SHADOWGRP
132 /*
133  * cleanup_report_add_group_gshadow - Report failure to add a group to gshadow
134  *
135  * It should be registered when it is decided to add a group to the
136  * gshadow database.
137  */
138 void cleanup_report_add_group_gshadow (void *group_name)
139 {
140         const char *name = (const char *)group_name;
141
142         SYSLOG ((LOG_ERR, "failed to add group %s to %s", name, sgr_dbname ()));
143 #ifdef WITH_AUDIT
144         audit_logger (AUDIT_ADD_GROUP, Prog,
145                       "adding group to /etc/gshadow",
146                       name, AUDIT_NO_ID,
147                       SHADOW_AUDIT_FAILURE);
148 #endif
149 }
150 #endif
151
152 /*
153  * cleanup_report_del_group_group - Report failure to remove a group from the
154  *                                  regular group database
155  *
156  * It should be registered when it is decided to remove a group from the
157  * regular group database.
158  */
159 void cleanup_report_del_group_group (void *group_name)
160 {
161         const char *name = (const char *)group_name;
162
163         SYSLOG ((LOG_ERR,
164                  "failed to remove group %s from %s",
165                  name, gr_dbname ()));
166 #ifdef WITH_AUDIT
167         audit_logger (AUDIT_ADD_GROUP, Prog,
168                       "removing group from /etc/group",
169                       name, AUDIT_NO_ID,
170                       SHADOW_AUDIT_FAILURE);
171 #endif
172 }
173
174 #ifdef SHADOWGRP
175 /*
176  * cleanup_report_del_group_gshadow - Report failure to remove a group from
177  *                                    gshadow
178  *
179  * It should be registered when it is decided to remove a group from the
180  * gshadow database.
181  */
182 void cleanup_report_del_group_gshadow (void *group_name)
183 {
184         const char *name = (const char *)group_name;
185
186         SYSLOG ((LOG_ERR,
187                  "failed to remove group %s from %s",
188                  name, sgr_dbname ()));
189 #ifdef WITH_AUDIT
190         audit_logger (AUDIT_ADD_GROUP, Prog,
191                       "removing group from /etc/gshadow",
192                       name, AUDIT_NO_ID,
193                       SHADOW_AUDIT_FAILURE);
194 #endif
195 }
196 #endif
197
198 /*
199  * cleanup_unlock_group - Unlock the group file
200  *
201  * It should be registered after the group file is successfully locked.
202  */
203 void cleanup_unlock_group (unused void *arg)
204 {
205         if (gr_unlock () == 0) {
206                 fprintf (stderr,
207                          _("%s: failed to unlock %s\n"),
208                          Prog, gr_dbname ());
209                 SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
210 #ifdef WITH_AUDIT
211                 audit_logger_message ("unlocking group file",
212                                       SHADOW_AUDIT_FAILURE);
213 #endif
214         }
215 }
216
217 #ifdef SHADOWGRP
218 /*
219  * cleanup_unlock_gshadow - Unlock the gshadow file
220  *
221  * It should be registered after the gshadow file is successfully locked.
222  */
223 void cleanup_unlock_gshadow (unused void *arg)
224 {
225         if (sgr_unlock () == 0) {
226                 fprintf (stderr,
227                          _("%s: failed to unlock %s\n"),
228                          Prog, sgr_dbname ());
229                 SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
230 #ifdef WITH_AUDIT
231                 audit_logger_message ("unlocking gshadow file",
232                                       SHADOW_AUDIT_FAILURE);
233 #endif
234         }
235 }
236 #endif
237