1
From ebiederm@xmission.com Tue Jan 22 09:18:47 2013
2
Return-Path: <ebiederm@xmission.com>
3
X-Original-To: serge@hallyn.com
4
Delivered-To: serge@hallyn.com
5
Received: by mail.hallyn.com (Postfix, from userid 5001)
6
id F2E6AC80F6; Tue, 22 Jan 2013 09:18:46 +0000 (UTC)
7
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail
9
X-Spam-Status: No, score=0.1 required=8.0 tests=BAD_ENC_HEADER,BAYES_00
10
autolearn=no version=3.3.1
11
Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232])
12
(using TLSv1 with cipher AES256-SHA (256/256 bits))
13
(No client certificate requested)
14
by mail.hallyn.com (Postfix) with ESMTPS id 996B1C80D1
15
for <serge@hallyn.com>; Tue, 22 Jan 2013 09:18:42 +0000 (UTC)
16
Received: from out03.mta.xmission.com ([166.70.13.233])
17
by out02.mta.xmission.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
19
(envelope-from <ebiederm@xmission.com>)
20
id 1TxZyW-0008Bi-3X; Tue, 22 Jan 2013 02:17:00 -0700
21
Received: from in02.mta.xmission.com ([166.70.13.52])
22
by out03.mta.xmission.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
24
(envelope-from <ebiederm@xmission.com>)
25
id 1TxZyU-0005NA-Qm; Tue, 22 Jan 2013 02:16:59 -0700
26
Received: from c-98-207-153-68.hsd1.ca.comcast.net ([98.207.153.68] helo=eric-ThinkPad-X220.xmission.com)
27
by in02.mta.xmission.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16)
29
(envelope-from <ebiederm@xmission.com>)
30
id 1TxZyQ-0004qs-T1; Tue, 22 Jan 2013 02:16:58 -0700
31
From: ebiederm@xmission.com (Eric W. Biederman)
32
To: Nicolas =?utf-8?Q?Fran=C3=A7ois?= <nicolas.francois@centraliens.net>
33
Cc: <Pkg-shadow-devel@lists.alioth.debian.org>, Linux Containers <containers@lists.linux-foundation.org>, "Michael Kerrisk \(man-pages\)" <mtk.manpages@gmail.com>, "Serge E. Hallyn" <serge@hallyn.com>
34
References: <87d2wxshu0.fsf@xmission.com>
35
Date: Tue, 22 Jan 2013 01:16:51 -0800
36
In-Reply-To: <87d2wxshu0.fsf@xmission.com> (Eric W. Biederman's message of
37
"Tue, 22 Jan 2013 01:11:19 -0800")
38
Message-ID: <878v7lr30c.fsf@xmission.com>
39
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)
41
Content-Type: text/plain
42
X-XM-AID: U2FsdGVkX1/1l7dElNy9uNLAXx8eC28OMs/pxPM8NEo=
43
X-SA-Exim-Connect-IP: 98.207.153.68
44
X-SA-Exim-Mail-From: ebiederm@xmission.com
45
Subject: [PATCH 06/11] userdel: Add support for removing subordinate user and group ids.
46
X-SA-Exim-Version: 4.2.1 (built Wed, 14 Nov 2012 14:26:46 -0700)
47
X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com)
54
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
56
src/userdel.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
1 files changed, 115 insertions(+), 0 deletions(-)
59
Index: shadow/src/userdel.c
60
===================================================================
61
--- shadow.orig/src/userdel.c 2013-02-01 15:27:52.380080367 -0600
62
+++ shadow/src/userdel.c 2013-02-01 15:27:52.372080367 -0600
66
#include "exitcodes.h"
67
+#include "subordinateio.h"
72
#define E_GRP_UPDATE 10 /* can't update group file */
73
#define E_HOMEDIR 12 /* can't remove home directory */
74
#define E_SE_UPDATE 14 /* can't update SELinux user mapping */
75
+#define E_SUB_UID_UPDATE 16 /* can't update the subordinate uid file */
76
+#define E_SUB_GID_UPDATE 18 /* can't update the subordinate gid file */
81
static bool is_shadow_grp;
82
static bool sgr_locked = false;
83
#endif /* SHADOWGRP */
84
+static bool is_sub_uid;
85
+static bool is_sub_gid;
86
static bool pw_locked = false;
87
static bool gr_locked = false;
88
static bool spw_locked = false;
89
+static bool sub_uid_locked = false;
90
+static bool sub_gid_locked = false;
92
/* local function prototypes */
93
static void usage (int status);
97
#endif /* SHADOWGRP */
100
+ if (sub_uid_close () == 0) {
101
+ fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname ());
102
+ SYSLOG ((LOG_ERR, "failure while writing changes to %s", sub_uid_dbname ()));
103
+ fail_exit (E_SUB_UID_UPDATE);
105
+ if (sub_uid_unlock () == 0) {
106
+ fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ());
107
+ SYSLOG ((LOG_ERR, "failed to unlock %s", sub_uid_dbname ()));
110
+ sub_uid_locked = false;
114
+ if (sub_gid_close () == 0) {
115
+ fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname ());
116
+ SYSLOG ((LOG_ERR, "failure while writing changes to %s", sub_gid_dbname ()));
117
+ fail_exit (E_SUB_GID_UPDATE);
119
+ if (sub_gid_unlock () == 0) {
120
+ fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname ());
121
+ SYSLOG ((LOG_ERR, "failed to unlock %s", sub_gid_dbname ()));
124
+ sub_gid_locked = false;
132
#endif /* SHADOWGRP */
133
+ if (sub_uid_locked) {
134
+ if (sub_uid_unlock () == 0) {
135
+ fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ());
136
+ SYSLOG ((LOG_ERR, "failed to unlock %s", sub_uid_dbname ()));
140
+ if (sub_gid_locked) {
141
+ if (sub_gid_unlock () == 0) {
142
+ fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname ());
143
+ SYSLOG ((LOG_ERR, "failed to unlock %s", sub_gid_dbname ()));
149
audit_logger (AUDIT_DEL_USER, Prog,
153
#endif /* SHADOWGRP */
155
+ if (sub_uid_lock () == 0) {
157
+ _("%s: cannot lock %s; try again later.\n"),
158
+ Prog, sub_uid_dbname ());
160
+ audit_logger (AUDIT_DEL_USER, Prog,
161
+ "locking subordinate user file",
162
+ user_name, (unsigned int) user_id,
163
+ SHADOW_AUDIT_FAILURE);
164
+#endif /* WITH_AUDIT */
165
+ fail_exit (E_SUB_UID_UPDATE);
167
+ sub_uid_locked = true;
168
+ if (sub_uid_open (O_RDWR) == 0) {
170
+ _("%s: cannot open %s\n"), Prog, sub_uid_dbname ());
172
+ audit_logger (AUDIT_DEL_USER, Prog,
173
+ "opening subordinate user file",
174
+ user_name, (unsigned int) user_id,
175
+ SHADOW_AUDIT_FAILURE);
176
+#endif /* WITH_AUDIT */
177
+ fail_exit (E_SUB_UID_UPDATE);
181
+ if (sub_gid_lock () == 0) {
183
+ _("%s: cannot lock %s; try again later.\n"),
184
+ Prog, sub_gid_dbname ());
186
+ audit_logger (AUDIT_DEL_USER, Prog,
187
+ "locking subordinate group file",
188
+ user_name, (unsigned int) user_id,
189
+ SHADOW_AUDIT_FAILURE);
190
+#endif /* WITH_AUDIT */
191
+ fail_exit (E_SUB_GID_UPDATE);
193
+ sub_gid_locked = true;
194
+ if (sub_gid_open (O_RDWR) == 0) {
196
+ _("%s: cannot open %s\n"), Prog, sub_gid_dbname ());
198
+ audit_logger (AUDIT_DEL_USER, Prog,
199
+ "opening subordinate group file",
200
+ user_name, (unsigned int) user_id,
201
+ SHADOW_AUDIT_FAILURE);
202
+#endif /* WITH_AUDIT */
203
+ fail_exit (E_SUB_GID_UPDATE);
210
Prog, user_name, spw_dbname ());
211
fail_exit (E_PW_UPDATE);
213
+ if (is_sub_uid && sub_uid_remove(user_name, 0, ULONG_MAX) == 0) {
215
+ _("%s: cannot remove entry %lu from %s\n"),
216
+ Prog, (unsigned long)user_id, sub_uid_dbname ());
217
+ fail_exit (E_SUB_UID_UPDATE);
219
+ if (is_sub_gid && sub_gid_remove(user_name, 0, ULONG_MAX) == 0) {
221
+ _("%s: cannot remove entry %lu from %s\n"),
222
+ Prog, (unsigned long)user_id, sub_gid_dbname ());
223
+ fail_exit (E_SUB_GID_UPDATE);
226
audit_logger (AUDIT_DEL_USER, Prog,
227
"deleting user entries",
230
is_shadow_grp = sgr_file_present ();
231
#endif /* SHADOWGRP */
232
+ is_sub_uid = sub_uid_file_present ();
233
+ is_sub_gid = sub_gid_file_present ();
236
* Start with a quick check to see if the user exists.