~serge-hallyn/ubuntu/raring/shadow/shadow-userns

« back to all changes in this revision

Viewing changes to debian/patches/userns/06_userns_userdel

  • Committer: Serge Hallyn
  • Date: 2013-02-01 21:31:48 UTC
  • Revision ID: serge.hallyn@canonical.com-20130201213148-6ms9125tjn2lngnq
Add patchset by Eric Biederman to support subids for use by unprivileged
users to administer private user namespaces.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
8
X-Spam-Level: 
 
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)
 
18
        (Exim 4.76)
 
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)
 
23
        (Exim 4.76)
 
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)
 
28
        (Exim 4.76)
 
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)
 
40
MIME-Version: 1.0
 
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)
 
48
X-UID: 2076                                        
 
49
Status: O
 
50
Content-Length: 5573
 
51
Lines: 186
 
52
 
 
53
 
 
54
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
 
55
---
 
56
 src/userdel.c |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
57
 1 files changed, 115 insertions(+), 0 deletions(-)
 
58
 
 
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
 
63
@@ -65,6 +65,7 @@
 
64
 #endif                         /* WITH_TCB */
 
65
 /*@-exitarg@*/
 
66
 #include "exitcodes.h"
 
67
+#include "subordinateio.h"
 
68
 
 
69
 /*
 
70
  * exit status values
 
71
@@ -75,6 +76,8 @@
 
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 */
 
77
 
 
78
 /*
 
79
  * Global variables
 
80
@@ -96,9 +99,13 @@
 
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;
 
91
 
 
92
 /* local function prototypes */
 
93
 static void usage (int status);
 
94
@@ -437,6 +444,34 @@
 
95
                sgr_locked = false;
 
96
        }
 
97
 #endif                         /* SHADOWGRP */
 
98
+
 
99
+       if (is_sub_uid) {
 
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);
 
104
+               }
 
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 ()));
 
108
+                       /* continue */
 
109
+               }
 
110
+               sub_uid_locked = false;
 
111
+       }
 
112
+
 
113
+       if (is_sub_gid) {
 
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);
 
118
+               }
 
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 ()));
 
122
+                       /* continue */
 
123
+               }
 
124
+               sub_gid_locked = false;
 
125
+       }
 
126
 }
 
127
 
 
128
 /*
 
129
@@ -474,6 +509,20 @@
 
130
                }
 
131
        }
 
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 ()));
 
137
+                       /* continue */
 
138
+               }
 
139
+       }
 
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 ()));
 
144
+                       /* continue */
 
145
+               }
 
146
+       }
 
147
 
 
148
 #ifdef WITH_AUDIT
 
149
        audit_logger (AUDIT_DEL_USER, Prog,
 
150
@@ -595,6 +644,58 @@
 
151
                }
 
152
        }
 
153
 #endif                         /* SHADOWGRP */
 
154
+       if (is_sub_uid) {
 
155
+               if (sub_uid_lock () == 0) {
 
156
+                       fprintf (stderr,
 
157
+                               _("%s: cannot lock %s; try again later.\n"),
 
158
+                               Prog, sub_uid_dbname ());
 
159
+#ifdef WITH_AUDIT
 
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);
 
166
+               }
 
167
+               sub_uid_locked = true;
 
168
+               if (sub_uid_open (O_RDWR) == 0) {
 
169
+                       fprintf (stderr,
 
170
+                               _("%s: cannot open %s\n"), Prog, sub_uid_dbname ());
 
171
+#ifdef WITH_AUDIT
 
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);
 
178
+               }
 
179
+       }
 
180
+       if (is_sub_gid) {
 
181
+               if (sub_gid_lock () == 0) {
 
182
+                       fprintf (stderr,
 
183
+                               _("%s: cannot lock %s; try again later.\n"),
 
184
+                               Prog, sub_gid_dbname ());
 
185
+#ifdef WITH_AUDIT
 
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);
 
192
+               }
 
193
+               sub_gid_locked = true;
 
194
+               if (sub_gid_open (O_RDWR) == 0) {
 
195
+                       fprintf (stderr,
 
196
+                               _("%s: cannot open %s\n"), Prog, sub_gid_dbname ());
 
197
+#ifdef WITH_AUDIT
 
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);
 
204
+               }
 
205
+       }
 
206
 }
 
207
 
 
208
 /*
 
209
@@ -619,6 +720,18 @@
 
210
                         Prog, user_name, spw_dbname ());
 
211
                fail_exit (E_PW_UPDATE);
 
212
        }
 
213
+       if (is_sub_uid && sub_uid_remove(user_name, 0, ULONG_MAX) == 0) {
 
214
+               fprintf (stderr,
 
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);
 
218
+       }
 
219
+       if (is_sub_gid && sub_gid_remove(user_name, 0, ULONG_MAX) == 0) {
 
220
+               fprintf (stderr,
 
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);
 
224
+       }
 
225
 #ifdef WITH_AUDIT
 
226
        audit_logger (AUDIT_DEL_USER, Prog,
 
227
                      "deleting user entries",
 
228
@@ -966,6 +1079,8 @@
 
229
 #ifdef SHADOWGRP
 
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 ();
 
234
 
 
235
        /*
 
236
         * Start with a quick check to see if the user exists.